/// <summary> /// 初始化 /// </summary> /// <param name="_sReadIniPath">ReadIni.dll文件路径</param> /// <param name="_sReadIniDllPath">要读取的配置文件路径,包含文件名</param> public void InitVideoAx(string _sReadIniDllPath, string _sReadIniFilePath) { this.ucVGSHow.Dock = DockStyle.Fill; if (!m_bIsInitHikSucc) { //加载读取配置文件的api if (ReadIniAPI.LoadReadIniAPI(_sReadIniDllPath)) { ReadIniAPI.StartUp(_sReadIniFilePath, m_funcReadIniMsg); //读取配置文件 并存储起来 ReadIniAPI.GetValueWithTitleAndKey("PATH", "CapPicPath"); ReadIniAPI.GetValueWithTitleAndKey("PATH", "VsClientPath"); ReadIniAPI.GetValueWithTitleAndKey("PATH", "HikSDKPath"); } else { MessageBox.Show("加载ReadIni未成功"); } //加载海康api库 if (CHCNetSDK.NET_DVR_Init()) { m_bIsInitHikSucc = true; CHCNetSDK.NET_DVR_SetDVRMessageCallBack_V31(m_MsgCallbackHik, IntPtr.Zero); } } }
/// <summary> /// 初始化active控件 /// </summary> /// <param name="_sReadIniDllPath">ReadIni.dll的文件路径(包含文件路径)</param> /// <param name="_sReadIniFilePath">config.ini的文件路径(包含文件路径)</param> public void InitActiveX(string _sReadIniDllPath, string _sReadIniFilePath) { if (ReadIniAPI.LoadReadIniAPI(_sReadIniDllPath)) { ReadIniAPI.StartUp(_sReadIniFilePath, m_funcReadIniMsg); //读取配置文件 并存储起来 ReadIniAPI.GetValueWithTitleAndKey("PATH", "VsClientPath"); ReadIniAPI.GetValueWithTitleAndKey("PATH", "HikSDKPath"); } }
/// <summary> /// 初始化ActiveX /// </summary> /// <param name="_sReadIniDllPath">ReadIni.dll的路径</param> /// <param name="_sReadIniFilePath">要读取的配置文件路径,包含文件名</param> public void InitActiveX(string _sReadIniDllPath, string _sReadIniFilePath) { //加载读取配置文件的api if (ReadIniAPI.LoadReadIniAPI(_sReadIniDllPath)) { ReadIniAPI.StartUp(_sReadIniFilePath, m_funcReadIniMsg); //读取配置文件 并存储起来 ReadIniAPI.GetValueWithTitleAndKey("PATH", "CapPicPath"); ReadIniAPI.GetValueWithTitleAndKey("PATH", "VsClientPath"); ReadIniAPI.GetValueWithTitleAndKey("PATH", "HikSDKPath"); } else { MessageBox.Show("加载ReadIni未成功"); } //加载海康api库 if (CHCNetSDK.NET_DVR_Init()) { CHCNetSDK.NET_DVR_SetDVRMessageCallBack_V31(m_MsgCallbackHik, IntPtr.Zero); } }
/// <summary> /// 抓拍按钮点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void pbCapture_Click(object sender, EventArgs e) { //不是第一次选择文件夹 if (m_bIsFirstFloder) { switch (m_iType) { case 1: //自己api string CapPathPath = m_CapPath + "\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + m_strName + "\\"; CreateDir(CapPathPath); string CapPathSelf = CapPathPath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bmp"; if (CaptureBmp(CapPathSelf) >= 0) { MessageBox.Show("图片已保存", "提示"); } else { MessageBox.Show("图片保存失败", "提示"); } break; case 2: //海康api CHCNetSDK.NET_DVR_JPEGPARA JpegInfo = new CHCNetSDK.NET_DVR_JPEGPARA(); JpegInfo.wPicSize = 3; //3-UXGA(1600*1200), JpegInfo.wPicQuality = 2; //0-最好,1-较好,2-一般 string CapPathHikPath = m_CapPath + "\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + m_strName + "\\"; CreateDir(CapPathHikPath); string CapPathHik = CapPathHikPath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpeg"; if (CHCNetSDK.NET_DVR_CapturePicture(m_lHandle, CapPathHik)) { CHCNetSDK.NET_DVR_GetLastError(); m_bIsFirstFloder = true; MessageBox.Show("图片已保存", "提示"); } else { MessageBox.Show("图片保存失败", "提示"); } break; } } //第一次选择文件夹 else { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "请选择抓拍图片文件存储路径"; switch (m_iType) { case 1: //自己api if (dialog.ShowDialog() == DialogResult.OK) { m_CapPath = dialog.SelectedPath; //将路径写入到配置文件中 if (ReadIniAPI.SetValueWithTitleAndKey("PATH", "PATH.CapPicPath", m_CapPath)) { SetCapPathAll(); MessageBox.Show("配置抓拍文件存储路径成功", "提示"); } } string CapPathPath = m_CapPath + "\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + m_strName + "\\"; CreateDir(CapPathPath); string CapPathSelf = CapPathPath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bmp"; if (CaptureBmp(CapPathSelf) >= 0) { MessageBox.Show("图片已保存", "提示"); } else { MessageBox.Show("图片保存失败", "提示"); } break; case 2: //海康api CHCNetSDK.NET_DVR_JPEGPARA JpegInfo = new CHCNetSDK.NET_DVR_JPEGPARA(); JpegInfo.wPicSize = 3; //3-UXGA(1600*1200), JpegInfo.wPicQuality = 2; //0-最好,1-较好,2-一般 if (dialog.ShowDialog() == DialogResult.OK) { m_CapPath = dialog.SelectedPath; SetCapPathAll(); string CapPath = m_CapPath.Replace(@"\", @"\\"); //将路径写入到配置文件中 if (ReadIniAPI.SetValueWithTitleAndKey("PATH", "PATH.CapPicPath", CapPath)) { MessageBox.Show("配置抓拍文件存储路径成功", "提示"); } } string CapPathHikPath = m_CapPath + "\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + m_strName + "\\"; CreateDir(CapPathHikPath); string CapPathHik = CapPathHikPath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpeg"; if (CHCNetSDK.NET_DVR_CapturePicture(m_lHandle, CapPathHik)) { CHCNetSDK.NET_DVR_GetLastError(); m_bIsFirstFloder = true; MessageBox.Show("图片已保存", "提示"); } else { MessageBox.Show("图片保存失败", "提示"); } break; } } }
/// <summary> /// 抓拍图片 /// </summary> public void CaptureBmpEx() { if (m_iCamType != -1) { //说明配置文件中已经拥有文件的抓拍路径了 if (m_bIsFirstFloder) { switch (m_iCamType) { case 1: //自己api string CapPathPath = m_sCapPath + "\\"; ucSVideo.SetCapturePath(CapPathPath); ucSVideo.CaptureBmpEx(); break; case 2: //海康api string CapPathHikPath = m_sCapPath + "\\"; ucSVideo.SetCapPath(CapPathHikPath); ucSVideo.CaptureJpegHik(); break; } } //用户第一次抓拍,还没有抓拍路径 else { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "请选择抓拍图片文件存储路径"; switch (m_iCamType) { case 1: //自己api if (dialog.ShowDialog() == DialogResult.OK) { m_sCapPath = dialog.SelectedPath; m_sCapPath = m_sCapPath.Replace(@"\", @"\\"); //将路径写入到配置文件中 if (ReadIniAPI.SetValueWithTitleAndKey("PATH", "PATH.CapPicPath", m_sCapPath)) { MessageBox.Show("配置抓拍文件存储路径成功", "提示"); } } string CapPathPath = m_sCapPath + "\\"; ucSVideo.SetCapturePath(CapPathPath); ucSVideo.CaptureBmpEx(); m_bIsFirstFloder = true; break; case 2: //海康api CHCNetSDK.NET_DVR_JPEGPARA JpegInfo = new CHCNetSDK.NET_DVR_JPEGPARA(); JpegInfo.wPicSize = 3; //3-UXGA(1600*1200), JpegInfo.wPicQuality = 2; //0-最好,1-较好,2-一般 if (dialog.ShowDialog() == DialogResult.OK) { m_sCapPath = dialog.SelectedPath; m_sCapPath = m_sCapPath.Replace(@"\", @"\\"); //将路径写入到配置文件中 if (ReadIniAPI.SetValueWithTitleAndKey("PATH", "PATH.CapPicPath", m_sCapPath)) { MessageBox.Show("配置抓拍文件存储路径成功", "提示"); } } string CapPathHikPath = m_sCapPath + "\\"; ucSVideo.SetCapPath(CapPathHikPath); ucSVideo.CaptureJpegHik(); m_bIsFirstFloder = true; break; } } } }