C#调用大华摄像头
2022/4/3 20:20:04
本文主要是介绍C#调用大华摄像头,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
大华SDK包地址:https://support.dahuatech.com/tools/sdkExploit
效果图:
//32位SDK 大华摄像机打开方法 IntPtr _LoginID = IntPtr.Zero; NET_DEVICEINFO_Ex _DeviceInfo = new NET_DEVICEINFO_Ex(); IntPtr _PlayID = IntPtr.Zero; IntPtr _PlayID2 = IntPtr.Zero; fAnalyzerDataCallBack _AnalyzerDataCallBack; TextInfo _TextInfo = Thread.CurrentThread.CurrentCulture.TextInfo; fDisConnectCallBack _DisConnectCallBack; //重连函数 fHaveReConnectCallBack _ReConnectCallBack;
1、登录方法
private void button_login_Click(object sender, EventArgs e) { //登录设备 try { //自动重连 NETClient.Init(_DisConnectCallBack, IntPtr.Zero, null); NETClient.SetAutoReconnect(_ReConnectCallBack, IntPtr.Zero); ushort port = Convert.ToUInt16(this.textBox_port.Text.Trim()); //端口 string username = this.textBox_name.Text.Trim();//账号 string password = this.textBox_password.Text.Trim(); //密码 _LoginID = NETClient.Login(this.textBox_ip.Text.Trim(), port, username, password, EM_LOGIN_SPAC_CAP_TYPE.TCP, IntPtr.Zero, ref _DeviceInfo); if (IntPtr.Zero == _LoginID) { MessageBox.Show(NETClient.GetLastError()); return; } //MessageBox.Show("登陆成功!"); //打开摄像头 button_play_Click(null, null); } catch (Exception ex) { //异常提示 MessageBox.Show(ex.Message); Process.GetCurrentProcess().Kill(); } }View Code
2.打开监控
private void button1_Click(object sender, EventArgs e) { //打开监控 if (button1.Text=="打开监控") { button_login_Click(null, null); button1.Text = "关闭监控"; } else { //关闭窗体关闭摄像头 _PlayID = IntPtr.Zero; _PlayID2 = IntPtr.Zero; this.pictureBox_play.Refresh(); button1.Text = "打开监控"; } }View Code
3.调用监控方法
private void button_play_Click(object sender, EventArgs e) { //打开监视 try { _PlayID = NETClient.RealPlay(_LoginID, _DeviceInfo.nChanNum - 1, this.pictureBox_play.Handle); _PlayID2 = NETClient.RealPlay(_LoginID, _DeviceInfo.nChanNum - 1, this.pictureBox_play2.Handle); if (IntPtr.Zero == _PlayID || IntPtr.Zero == _PlayID2) { MessageBox.Show(NETClient.GetLastError()); return; } bool ret = NETClient.RenderPrivateData(_PlayID, true); if (!ret) { MessageBox.Show(NETClient.GetLastError()); return; } } catch (Exception) { //异常提示 throw; } }View Code
4.关闭窗体时自动关闭监控
private void DaHua_32_FormClosing(object sender, FormClosingEventArgs e) { //关闭窗体关闭摄像头 _PlayID = IntPtr.Zero; _PlayID2 = IntPtr.Zero; this.pictureBox_play.Refresh(); }View Code
其他:
1.三个实体类
2.dll
这两个东西从https://support.dahuatech.com/tools/sdkExploit里面下载
这篇关于C#调用大华摄像头的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-03-01沐雪多租宝商城源码从.NetCore3.1升级到.Net6的步骤
- 2024-12-06使用Microsoft.Extensions.AI在.NET中生成嵌入向量
- 2024-11-18微软研究:RAG系统的四个层次提升理解与回答能力
- 2024-11-15C#中怎么从PEM格式的证书中提取公钥?-icode9专业技术文章分享
- 2024-11-14云架构设计——如何用diagrams.net绘制专业的AWS架构图?
- 2024-05-08首个适配Visual Studio平台的国产智能编程助手CodeGeeX正式上线!C#程序员必备效率神器!
- 2024-03-30C#设计模式之十六迭代器模式(Iterator Pattern)【行为型】
- 2024-03-29c# datetime tryparse
- 2024-02-21list find index c#
- 2024-01-24convert toint32 c#