C#呼叫大華攝像頭
阿新 • • 發佈:2022-04-03
大華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 { //自動重連View CodeNETClient.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();//賬號 stringpassword = 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(); } }
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裡面下載