大華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(); } }
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 = "打開監控"; } }
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; } }
4.關閉窗體時自動關閉監控

private void DaHua_32_FormClosing(object sender, FormClosingEventArgs e) { //關閉窗體關閉攝像頭 _PlayID = IntPtr.Zero; _PlayID2 = IntPtr.Zero; this.pictureBox_play.Refresh(); }
其他:
1.三個實體類
2.dll
這兩個東西從https://support.dahuatech.com/tools/sdkExploit里面下載