实例介绍
【实例简介】
【Demo内容说明】
-------------------------------------
1. 实现预览、抓图(BMP、JPEG)、客户端录像、云台控制(2014-7-4)
2. 设备通道号在界面上手动输入,64路以下NVR的IP通道一般从33开始
3. bin文件夹下为已编译的可执行程序(Release版本)
4. SDK日志保存路径:"C:\\SdkLog\\"(2014-7-4)
【注意事项】
------------------------------------
1. 请到海康威视官网下载最新版本设备网络SDK:http://www.hikvision.com/Cn/download_more_401.html
2. 请将设备网络SDK开发包【库文件】里的HCNetSDK.dll、HCCore.dll、HCNetSDKCom文件夹、PlayCtrl.dll、SuperRender.dll、AudioRender.dll、ssleay32.dll、libeay32.dll、hlog.dll、hpr.dll、zlib1.dll、log4cxx.properties等文件均拷贝到bin文件夹下。HCNetSDKCom文件夹(包含里面的功能组件dll库文件)需要和HCNetSDK.dll、HCCore.dll一起加载,放在同一个目录下,且HCNetSDKCom文件夹名不能修改。
3. 如果自行开发软件不能正常实现相应功能,而且程序没有指定加载的dll库路径,请在程序运行的情况下尝试删除HCNetSDK.dll。如果可以删除,说明程序可能调用到系统盘Windows->System32目录下的dll文件,建议删除或者更新该目录下的相关dll文件;如果不能删除,dll文件右键选择属性确认SDK库版本。
4. 如按上述步骤操作后还是不能实现相应功能,请根据NET_DVR_GetLastError返回的错误号判断原因。
【实例截图】
【核心代码】
namespace PreviewDemo { /// <summary> /// Form1 的摘要说明。 /// </summary> public class Preview : System.Windows.Forms.Form { private uint iLastErr = 0; private Int32 m_lUserID = -1; private bool m_bInitSDK = false; private bool m_bRecord = false; private bool m_bTalk = false; private Int32 m_lRealHandle = -1; private int lVoiceComHandle = -1; private string str; CHCNetSDK.REALDATACALLBACK RealData = null; CHCNetSDK.LOGINRESULTCALLBACK LoginCallBack = null; public CHCNetSDK.NET_DVR_PTZPOS m_struPtzCfg; public CHCNetSDK.NET_DVR_USER_LOGIN_INFO struLogInfo; public CHCNetSDK.NET_DVR_DEVICEINFO_V40 DeviceInfo; public delegate void UpdateTextStatusCallback(string strLogStatus, IntPtr lpDeviceInfo); private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; private System.Windows.Forms.Button btnLogin; private System.Windows.Forms.Button btnPreview; private System.Windows.Forms.PictureBox RealPlayWnd; private TextBox textBoxIP; private TextBox textBoxPort; private TextBox textBoxUserName; private TextBox textBoxPassword; private Label label5; private Label label6; private Label label7; private Label label8; private Label label9; private Label label10; private Button btnBMP; private Button btnJPEG; private Label label11; private Label label12; private Label label13; private TextBox textBoxChannel; private Button btnRecord; private Label label14; private Button btn_Exit; private Button btnVioceTalk; private Label label16; private Label label17; private TextBox textBoxID; /*private Button PtzGet; private Button PtzSet;*/ private Label label19; /*private ComboBox comboBox1; private TextBox textBoxPanPos; private TextBox textBoxTiltPos; private TextBox textBoxZoomPos;*/ private Label label20; private Label label21; private Label label22; private Button PreSet; private Label label23; private Label labelLogin; //private GroupBox groupBox1; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Preview() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); m_bInitSDK = CHCNetSDK.NET_DVR_Init(); if (m_bInitSDK == false) { MessageBox.Show("NET_DVR_Init error!"); return; } else { //保存SDK日志 To save the SDK log CHCNetSDK.NET_DVR_SetLogToFile(3, "C:\\SdkLog\\", true); } // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if (m_lRealHandle >= 0) { CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle); } if (m_lUserID >= 0) { CHCNetSDK.NET_DVR_Logout(m_lUserID); } if (m_bInitSDK == true) { CHCNetSDK.NET_DVR_Cleanup(); } if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.btnLogin = new System.Windows.Forms.Button(); this.btnPreview = new System.Windows.Forms.Button(); this.RealPlayWnd = new System.Windows.Forms.PictureBox(); this.textBoxIP = new System.Windows.Forms.TextBox(); this.textBoxPort = new System.Windows.Forms.TextBox(); this.textBoxUserName = new System.Windows.Forms.TextBox(); this.textBoxPassword = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.label8 = new System.Windows.Forms.Label(); this.label9 = new System.Windows.Forms.Label(); this.label10 = new System.Windows.Forms.Label(); this.btnBMP = new System.Windows.Forms.Button(); this.btnJPEG = new System.Windows.Forms.Button(); this.label11 = new System.Windows.Forms.Label(); this.label12 = new System.Windows.Forms.Label(); this.label13 = new System.Windows.Forms.Label(); this.textBoxChannel = new System.Windows.Forms.TextBox(); this.btnRecord = new System.Windows.Forms.Button(); this.label14 = new System.Windows.Forms.Label(); this.btn_Exit = new System.Windows.Forms.Button(); this.btnVioceTalk = new System.Windows.Forms.Button(); this.label16 = new System.Windows.Forms.Label(); this.label17 = new System.Windows.Forms.Label(); this.textBoxID = new System.Windows.Forms.TextBox(); this.PreSet = new System.Windows.Forms.Button(); this.label23 = new System.Windows.Forms.Label(); this.labelLogin = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.RealPlayWnd)).BeginInit(); this.SuspendLayout(); // // label1 // this.label1.Location = new System.Drawing.Point(12, 14); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(74, 18); this.label1.TabIndex = 0; this.label1.Text = "Device IP"; // // label2 // this.label2.Location = new System.Drawing.Point(12, 59); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(62, 16); this.label2.TabIndex = 0; this.label2.Text = "User Name"; // // label3 // this.label3.Location = new System.Drawing.Point(234, 58); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(63, 16); this.label3.TabIndex = 0; this.label3.Text = "Password"; // // label4 // this.label4.Location = new System.Drawing.Point(234, 14); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(79, 17); this.label4.TabIndex = 0; this.label4.Text = "Device Port"; // // btnLogin // this.btnLogin.Location = new System.Drawing.Point(435, 38); this.btnLogin.Name = "btnLogin"; this.btnLogin.Size = new System.Drawing.Size(78, 50); this.btnLogin.TabIndex = 1; this.btnLogin.Text = "Login"; this.btnLogin.Click = new System.EventHandler(this.btnLogin_Click); // // btnPreview // this.btnPreview.Location = new System.Drawing.Point(17, 571); this.btnPreview.Name = "btnPreview"; this.btnPreview.Size = new System.Drawing.Size(76, 34); this.btnPreview.TabIndex = 7; this.btnPreview.Text = "Live View"; this.btnPreview.Click = new System.EventHandler(this.btnPreview_Click); // // RealPlayWnd // this.RealPlayWnd.BackColor = System.Drawing.SystemColors.WindowText; this.RealPlayWnd.Location = new System.Drawing.Point(18, 131); this.RealPlayWnd.Name = "RealPlayWnd"; this.RealPlayWnd.Size = new System.Drawing.Size(495, 378); this.RealPlayWnd.TabIndex = 4; this.RealPlayWnd.TabStop = false; // // textBoxIP // this.textBoxIP.Location = new System.Drawing.Point(78, 24); this.textBoxIP.Name = "textBoxIP"; this.textBoxIP.Size = new System.Drawing.Size(114, 21); this.textBoxIP.TabIndex = 2; this.textBoxIP.Text = "10.18.37.120"; // // textBoxPort // this.textBoxPort.Location = new System.Drawing.Point(308, 24); this.textBoxPort.Name = "textBoxPort"; this.textBoxPort.Size = new System.Drawing.Size(112, 21); this.textBoxPort.TabIndex = 3; this.textBoxPort.Text = "8000"; // // textBoxUserName // this.textBoxUserName.Location = new System.Drawing.Point(78, 70); this.textBoxUserName.Name = "textBoxUserName"; this.textBoxUserName.Size = new System.Drawing.Size(114, 21); this.textBoxUserName.TabIndex = 4; this.textBoxUserName.Text = "admin"; // // textBoxPassword // this.textBoxPassword.Cursor = System.Windows.Forms.Cursors.IBeam; this.textBoxPassword.Location = new System.Drawing.Point(308, 70); this.textBoxPassword.Name = "textBoxPassword"; this.textBoxPassword.PasswordChar = '*'; this.textBoxPassword.Size = new System.Drawing.Size(112, 21); this.textBoxPassword.TabIndex = 5; this.textBoxPassword.Text = "abcd1234"; // // label5 // this.label5.AutoSize = true; this.label5.Location = new System.Drawing.Point(12, 33); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(41, 12); this.label5.TabIndex = 9; this.label5.Text = "设备IP"; // // label6 // this.label6.AutoSize = true; this.label6.Location = new System.Drawing.Point(234, 33); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(53, 12); this.label6.TabIndex = 10; this.label6.Text = "设备端口"; // // label7 // this.label7.AutoSize = true; this.label7.Location = new System.Drawing.Point(14, 79); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(41, 12); this.label7.TabIndex = 11; this.label7.Text = "用户名"; // // label8 // this.label8.AutoSize = true; this.label8.Location = new System.Drawing.Point(236, 79); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(29, 12); this.label8.TabIndex = 12; this.label8.Text = "密码"; // // label9 // this.label9.AutoSize = true; this.label9.Location = new System.Drawing.Point(18, 550); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(29, 12); this.label9.TabIndex = 13; this.label9.Text = "预览"; // // label10 // this.label10.AutoSize = true; this.label10.Location = new System.Drawing.Point(442, 19); this.label10.Name = "label10"; this.label10.Size = new System.Drawing.Size(29, 12); this.label10.TabIndex = 14; this.label10.Text = "登录"; // // btnBMP // this.btnBMP.Location = new System.Drawing.Point(110, 572); this.btnBMP.Name = "btnBMP"; this.btnBMP.Size = new System.Drawing.Size(79, 34); this.btnBMP.TabIndex = 8; this.btnBMP.Text = "Capture BMP "; this.btnBMP.UseVisualStyleBackColor = true; this.btnBMP.Click = new System.EventHandler(this.btnBMP_Click); // // btnJPEG // this.btnJPEG.Location = new System.Drawing.Point(208, 571); this.btnJPEG.Name = "btnJPEG"; this.btnJPEG.Size = new System.Drawing.Size(97, 34); this.btnJPEG.TabIndex = 9; this.btnJPEG.Text = "Capture JPEG"; this.btnJPEG.UseVisualStyleBackColor = true; this.btnJPEG.Click = new System.EventHandler(this.btnJPEG_Click); // // label11 // this.label11.AutoSize = true; this.label11.Location = new System.Drawing.Point(113, 550); this.label11.Name = "label11"; this.label11.Size = new System.Drawing.Size(47, 12); this.label11.TabIndex = 17; this.label11.Text = "BMP抓图"; // // label12 // this.label12.AutoSize = true; this.label12.Location = new System.Drawing.Point(214, 550); this.label12.Name = "label12"; this.label12.Size = new System.Drawing.Size(53, 12); this.label12.TabIndex = 18; this.label12.Text = "JPEG抓图"; // // label13 // this.label13.AutoSize = true; this.label13.Location = new System.Drawing.Point(17, 521); this.label13.Name = "label13"; this.label13.Size = new System.Drawing.Size(83, 12); this.label13.TabIndex = 19; this.label13.Text = "预览/抓图通道"; // // textBoxChannel // this.textBoxChannel.Location = new System.Drawing.Point(107, 517); this.textBoxChannel.Name = "textBoxChannel"; this.textBoxChannel.Size = new System.Drawing.Size(100, 21); this.textBoxChannel.TabIndex = 6; this.textBoxChannel.Text = "1"; // // btnRecord // this.btnRecord.Location = new System.Drawing.Point(319, 571); this.btnRecord.Name = "btnRecord"; this.btnRecord.Size = new System.Drawing.Size(100, 34); this.btnRecord.TabIndex = 10; this.btnRecord.Text = "Start Record"; this.btnRecord.UseVisualStyleBackColor = true; this.btnRecord.Click = new System.EventHandler(this.btnRecord_Click); // // label14 // this.label14.AutoSize = true; this.label14.Location = new System.Drawing.Point(320, 550); this.label14.Name = "label14"; this.label14.Size = new System.Drawing.Size(65, 12); this.label14.TabIndex = 22; this.label14.Text = "客户端录像"; // // btn_Exit // this.btn_Exit.Location = new System.Drawing.Point(438, 615); this.btn_Exit.Name = "btn_Exit"; this.btn_Exit.Size = new System.Drawing.Size(75, 32); this.btn_Exit.TabIndex = 11; this.btn_Exit.Tag = ""; this.btn_Exit.Text = "退出 Exit"; this.btn_Exit.UseVisualStyleBackColor = true; this.btn_Exit.Click = new System.EventHandler(this.btn_Exit_Click); // // btnVioceTalk // this.btnVioceTalk.Location = new System.Drawing.Point(18, 641); this.btnVioceTalk.Name = "btnVioceTalk"; this.btnVioceTalk.Size = new System.Drawing.Size(75, 34); this.btnVioceTalk.TabIndex = 25; this.btnVioceTalk.Text = "Start Talk"; this.btnVioceTalk.UseVisualStyleBackColor = true; this.btnVioceTalk.Click = new System.EventHandler(this.btnVioceTalk_Click); // // label16 // this.label16.AutoSize = true; this.label16.Location = new System.Drawing.Point(18, 621); this.label16.Name = "label16"; this.label16.Size = new System.Drawing.Size(53, 12); this.label16.TabIndex = 26; this.label16.Text = "语音对讲"; // // label17 // this.label17.AutoSize = true; this.label17.Location = new System.Drawing.Point(238, 520); this.label17.Name = "label17"; this.label17.Size = new System.Drawing.Size(29, 12); this.label17.TabIndex = 27; this.label17.Text = "流ID"; // // textBoxID // this.textBoxID.Location = new System.Drawing.Point(277, 516); this.textBoxID.Name = "textBoxID"; this.textBoxID.Size = new System.Drawing.Size(225, 21); this.textBoxID.TabIndex = 28; // // PreSet // this.PreSet.Location = new System.Drawing.Point(115, 641); this.PreSet.Name = "PreSet"; this.PreSet.Size = new System.Drawing.Size(97, 33); this.PreSet.TabIndex = 31; this.PreSet.Text = "PTZ Control"; this.PreSet.UseVisualStyleBackColor = true; this.PreSet.Click = new System.EventHandler(this.PreSet_Click); // // label23 // this.label23.AutoSize = true; this.label23.Location = new System.Drawing.Point(119, 621); this.label23.Name = "label23"; this.label23.Size = new System.Drawing.Size(53, 12); this.label23.TabIndex = 32; this.label23.Text = "云台控制"; // // labelLogin // this.labelLogin.AutoSize = true; this.labelLogin.Location = new System.Drawing.Point(105, 103); this.labelLogin.Name = "labelLogin"; this.labelLogin.Size = new System.Drawing.Size(113, 12); this.labelLogin.TabIndex = 33; this.labelLogin.Text = "登录状态(异步):"; // // Preview // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(531, 687); this.Controls.Add(this.labelLogin); this.Controls.Add(this.label23); this.Controls.Add(this.PreSet); this.Controls.Add(this.textBoxID); this.Controls.Add(this.label17); this.Controls.Add(this.label16); this.Controls.Add(this.btnVioceTalk); this.Controls.Add(this.btn_Exit); this.Controls.Add(this.label14); this.Controls.Add(this.btnRecord); this.Controls.Add(this.textBoxChannel); this.Controls.Add(this.label13); this.Controls.Add(this.label12); this.Controls.Add(this.label11); this.Controls.Add(this.btnJPEG); this.Controls.Add(this.btnBMP); this.Controls.Add(this.label10); this.Controls.Add(this.label9); this.Controls.Add(this.label8); this.Controls.Add(this.label7); this.Controls.Add(this.label6); this.Controls.Add(this.label5); this.Controls.Add(this.textBoxPassword); this.Controls.Add(this.textBoxUserName); this.Controls.Add(this.textBoxPort); this.Controls.Add(this.textBoxIP); this.Controls.Add(this.RealPlayWnd); this.Controls.Add(this.btnPreview); this.Controls.Add(this.btnLogin); this.Controls.Add(this.label1); this.Controls.Add(this.label2); this.Controls.Add(this.label3); this.Controls.Add(this.label4); this.Name = "Preview"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Preview"; this.Load = new System.EventHandler(this.Preview_Load); ((System.ComponentModel.ISupportInitialize)(this.RealPlayWnd)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Preview()); } private void textBox1_TextChanged(object sender, System.EventArgs e) { } public void UpdateClientList(string strLogStatus, IntPtr lpDeviceInfo) { //列表新增报警信息 labelLogin.Text = "登录状态(异步):" strLogStatus; } public void cbLoginCallBack(int lUserID, int dwResult, IntPtr lpDeviceInfo, IntPtr pUser) { string strLoginCallBack = "登录设备,lUserID:" lUserID ",dwResult:" dwResult; if (dwResult==0) { uint iErrCode = CHCNetSDK.NET_DVR_GetLastError(); strLoginCallBack = strLoginCallBack ",错误号:" iErrCode; } //下面代码注释掉也会崩溃 if (InvokeRequired) { object[] paras = new object[2]; paras[0] = strLoginCallBack; paras[1] = lpDeviceInfo; labelLogin.BeginInvoke(new UpdateTextStatusCallback(UpdateClientList), paras); } else { //创建该控件的主线程直接更新信息列表 UpdateClientList(strLoginCallBack, lpDeviceInfo); } } private void btnLogin_Click(object sender, System.EventArgs e) { if (textBoxIP.Text == "" || textBoxPort.Text == "" || textBoxUserName.Text == "" || textBoxPassword.Text == "") { MessageBox.Show("Please input IP, Port, User name and Password!"); return; } if (m_lUserID < 0) { struLogInfo = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO(); //设备IP地址或者域名 byte[] byIP = System.Text.Encoding.Default.GetBytes(textBoxIP.Text); struLogInfo.sDeviceAddress = new byte[129]; byIP.CopyTo(struLogInfo.sDeviceAddress, 0); //设备用户名 byte[] byUserName = System.Text.Encoding.Default.GetBytes(textBoxUserName.Text); struLogInfo.sUserName = new byte[64]; byUserName.CopyTo(struLogInfo.sUserName, 0); //设备密码 byte[] byPassword = System.Text.Encoding.Default.GetBytes(textBoxPassword.Text); struLogInfo.sPassword = new byte[64]; byPassword.CopyTo(struLogInfo.sPassword, 0); struLogInfo.wPort = ushort.Parse(textBoxPort.Text);//设备服务端口号 if (LoginCallBack == null) { LoginCallBack = new CHCNetSDK.LOGINRESULTCALLBACK(cbLoginCallBack);//注册回调函数 } struLogInfo.cbLoginResult = LoginCallBack; struLogInfo.bUseAsynLogin = false; //是否异步登录:0- 否,1- 是 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V40(); //登录设备 Login the device m_lUserID = CHCNetSDK.NET_DVR_Login_V40(ref struLogInfo, ref DeviceInfo); if (m_lUserID < 0) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_Login_V40 failed, error code= " iLastErr; //登录失败,输出错误号 MessageBox.Show(str); return; } else { //登录成功 MessageBox.Show("Login Success!"); btnLogin.Text = "Logout"; } } else { //注销登录 Logout the device if (m_lRealHandle >= 0) { MessageBox.Show("Please stop live view firstly"); return; } if (!CHCNetSDK.NET_DVR_Logout(m_lUserID)) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_Logout failed, error code= " iLastErr; MessageBox.Show(str); return; } m_lUserID = -1; btnLogin.Text = "Login"; } return; } private void btnPreview_Click(object sender, System.EventArgs e) { if(m_lUserID < 0) { MessageBox.Show("Please login the device firstly"); return; } if (m_lRealHandle < 0) { CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO(); lpPreviewInfo.hPlayWnd = RealPlayWnd.Handle;//预览窗口 lpPreviewInfo.lChannel = Int16.Parse(textBoxChannel.Text);//预te览的设备通道 lpPreviewInfo.dwStreamType = 0;//码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推 lpPreviewInfo.dwLinkMode = 0;//连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP lpPreviewInfo.bBlocked = true; //0- 非阻塞取流,1- 阻塞取流 lpPreviewInfo.dwDisplayBufNum = 1; //播放库播放缓冲区最大缓冲帧数 lpPreviewInfo.byProtoType = 0; lpPreviewInfo.byPreviewMode = 0; if (textBoxID.Text != "") { lpPreviewInfo.lChannel = -1; byte[] byStreamID = System.Text.Encoding.Default.GetBytes(textBoxID.Text); lpPreviewInfo.byStreamID = new byte[32]; byStreamID.CopyTo(lpPreviewInfo.byStreamID, 0); } if (RealData == null) { RealData = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack);//预览实时流回调函数 } IntPtr pUser = new IntPtr();//用户数据 //打开预览 Start live view m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null/*RealData*/, pUser); if (m_lRealHandle < 0) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_RealPlay_V40 failed, error code= " iLastErr; //预览失败,输出错误号 MessageBox.Show(str); return; } else { //预览成功 btnPreview.Text = "Stop Live View"; } } else { //停止预览 Stop live view if (!CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle)) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_StopRealPlay failed, error code= " iLastErr; MessageBox.Show(str); return; } m_lRealHandle = -1; btnPreview.Text = "Live View"; } return; } public void RealDataCallBack(Int32 lRealHandle, UInt32 dwDataType, IntPtr pBuffer, UInt32 dwBufSize, IntPtr pUser) { if (dwBufSize > 0) { byte[] sData = new byte[dwBufSize]; Marshal.Copy(pBuffer, sData, 0, (Int32)dwBufSize); string str = "实时流数据.ps"; FileStream fs = new FileStream(str, FileMode.Create); int iLen = (int)dwBufSize; fs.Write(sData, 0, iLen); fs.Close(); } } private void btnBMP_Click(object sender, EventArgs e) { string sBmpPicFileName; //图片保存路径和文件名 the path and file name to save sBmpPicFileName = "BMP_test.bmp"; //BMP抓图 Capture a BMP picture if (!CHCNetSDK.NET_DVR_CapturePicture(m_lRealHandle, sBmpPicFileName)) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_CapturePicture failed, error code= " iLastErr; MessageBox.Show(str); return; } else { str = "Successful to capture the BMP file and the saved file is " sBmpPicFileName; MessageBox.Show(str); } return; } private void btnJPEG_Click(object sender, EventArgs e) { string sJpegPicFileName; //图片保存路径和文件名 the path and file name to save sJpegPicFileName = "JPEG_test.jpg"; int lChannel = Int16.Parse(textBoxChannel.Text); //通道号 Channel number CHCNetSDK.NET_DVR_JPEGPARA lpJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA(); lpJpegPara.wPicQuality = 0; //图像质量 Image quality lpJpegPara.wPicSize = 0xff; //抓图分辨率 Picture size: 2- 4CIF,0xff- Auto(使用当前码流分辨率),抓图分辨率需要设备支持,更多取值请参考SDK文档 //JPEG抓图 Capture a JPEG picture if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, lChannel, ref lpJpegPara, sJpegPicFileName)) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_CaptureJPEGPicture failed, error code= " iLastErr; MessageBox.Show(str); return; } else { str = "Successful to capture the JPEG file and the saved file is " sJpegPicFileName; MessageBox.Show(str); } return; } private void btnRecord_Click(object sender, EventArgs e) { //录像保存路径和文件名 the path and file name to save string sVideoFileName; sVideoFileName = "Record_test.mp4"; if (m_bRecord == false) { //强制I帧 Make a I frame int lChannel = Int16.Parse(textBoxChannel.Text); //通道号 Channel number CHCNetSDK.NET_DVR_MakeKeyFrame(m_lUserID, lChannel); //开始录像 Start recording if (!CHCNetSDK.NET_DVR_SaveRealData(m_lRealHandle, sVideoFileName)) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_SaveRealData failed, error code= " iLastErr; MessageBox.Show(str); return; } else { btnRecord.Text = "Stop Record"; m_bRecord = true; } } else { //停止录像 Stop recording if (!CHCNetSDK.NET_DVR_StopSaveRealData(m_lRealHandle)) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_StopSaveRealData failed, error code= " iLastErr; MessageBox.Show(str); return; } else { str = "Successful to stop recording and the saved file is " sVideoFileName; MessageBox.Show(str); btnRecord.Text = "Start Record"; m_bRecord = false; } } return; } private void btn_Exit_Click(object sender, EventArgs e) { //停止预览 Stop live view if (m_lRealHandle >= 0) { CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle); m_lRealHandle = -1; } //注销登录 Logout the device if (m_lUserID >= 0) { CHCNetSDK.NET_DVR_Logout(m_lUserID); m_lUserID = -1; } CHCNetSDK.NET_DVR_Cleanup(); Application.Exit(); } private void btnPTZ_Click(object sender, EventArgs e) { } public void VoiceDataCallBack(int lVoiceComHandle, IntPtr pRecvDataBuffer, uint dwBufSize, byte byAudioFlag, System.IntPtr pUser) { byte[] sString = new byte[dwBufSize]; Marshal.Copy(pRecvDataBuffer, sString, 0, (Int32)dwBufSize); if (byAudioFlag ==0) { //将缓冲区里的音频数据写入文件 save the data into a file string str = "PC采集音频文件.pcm"; FileStream fs = new FileStream(str, FileMode.Create); int iLen = (int)dwBufSize; fs.Write(sString, 0, iLen); fs.Close(); } if (byAudioFlag == 1) { //将缓冲区里的音频数据写入文件 save the data into a file string str = "设备音频文件.pcm"; FileStream fs = new FileStream(str, FileMode.Create); int iLen = (int)dwBufSize; fs.Write(sString, 0, iLen); fs.Close(); } }
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论