C#调用大华摄像头

作者:@大木瓜
本文为作者原创,转载请注明出处:https://www.cnblogs.com/damugua/p/16096734.html


大华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里面下载

 

 

posted @   大木瓜  阅读(1882)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示