Ejemplo n.º 1
0
        public bool CaptureBmp(string filename, out string error)
        {
            error = "";

            #region 检验状态

            if (!m_bInitSDK)
            {
                error = $"error: 设备尚未初始化,请检查是否缺少海康威视所需的SDK";
                return(false);
            }
            if (m_lUserID < 0)
            {
                error = $"error: 设备未登录,请先登录.";
                return(false);
            }
            if (m_lRealHandle < 0)
            {
                error = $"error: 尚未加载视频,不能进行抓图.";
                return(false);
            }

            #endregion

            if (!CHCNetSDK.NET_DVR_CapturePicture(m_lRealHandle, filename))
            {
                error = "抓图错误,代码为:" + CHCNetSDK.NET_DVR_GetLastError();
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private void btnBMP_Click(object sender, EventArgs e)
        {
            if (m_lRealHandle < 0)
            {
                DebugInfo("Please start live view firstly!"); //BMP抓图需要先打开预览
                return;
            }

            string sBmpPicFileName;

            //图片保存路径和文件名 the path and file name to save
            sBmpPicFileName = "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;
                DebugInfo(str);
                return;
            }
            else
            {
                str = "NET_DVR_CapturePicture succ and the saved file is " + sBmpPicFileName;
                DebugInfo(str);

                //将图片显示到picturebox  dingyh
                loadCapturePic(null);
            }
            return;
        }
Ejemplo n.º 3
0
        // 抓图点击时 开始抓图
        private void cmsZT_Click(object sender, EventArgs e)
        {
            PictureBox pic   = (PictureBox)(cms.SourceControl);
            int        index = int.Parse(pic.Name);

            if (m_lRealHandle[index] >= 0)  // 抓图
            {
                string path = ClassXml.getSetXml("capture");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                //图片名称 年月日 时分秒
                string sBmpPicFileName = System.DateTime.Now.ToString("yyMMddhhmmss");
                sBmpPicFileName = path + "\\" + sBmpPicFileName + ".bmp";
                //BMP抓图 Capture a BMP picture
                if (!CHCNetSDK.NET_DVR_CapturePicture(m_lRealHandle[index], sBmpPicFileName))
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    toolStripStatusLabel6.Text = "抓图失败,错误代码" + iLastErr.ToString();
                }
                else
                {
                    toolStripStatusLabel6.Text = "抓图成功,保存文件名为" + sBmpPicFileName;
                }
            }
        }
Ejemplo n.º 4
0
        //抓图BMP
        public string saveBMP()
        {
            if (m_lRealHandle < 0)
            {
                MessageBox.Show("Please start live view firstly!"); //BMP抓图需要先打开预览
                return(null);
            }
            DateTime date = DateTime.Today;
            string   sBmpPicFileName;

            //图片保存路径和文件名 the path and file name to save
            //+ "-" + UserID + "_" + date.ToString("hh:mm:ss")
            sBmpPicFileName = "D:\\" + date.ToString("yyyy-MM-dd") + ".bmp";

            //BMP抓图 Capture a BMP picture
            if (!CHCNetSDK.NET_DVR_CapturePicture(m_lRealHandle, sBmpPicFileName))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                string str = "NET_DVR_CapturePicture failed, error code= " + iLastErr;
                MessageBox.Show(str);
                return(null);
            }
            else
            {
                string str = "Successful to capture the BMP file and the saved file is " + sBmpPicFileName;
                MessageBox.Show(str);
            }
            return(sBmpPicFileName);
        }
Ejemplo n.º 5
0
        private void btnBMP_Click(object sender, EventArgs e)//»ñȡͼƬ
        {
            string sBmpPicFileName;
            //ͼƬ±£´æ·¾¶ºÍÎļþÃû the path and file name to save
            string time_now = DateTime.Now.ToString("yyyyMMddHHmmssffff");

            sBmpPicFileName = "G:\\ÉãÏñÍ·ÅÄÕÕ\\" + time_now + ".JPEG";

            //CHCNetSDK.netdvrsetca;

            //BMPץͼ Capture a BMP picture
            if (!CHCNetSDK.NET_DVR_CapturePicture(m_lRealHandle[m_lRealHandle_flag], 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 \n" + sBmpPicFileName;
                MessageBox.Show(str);
            }
            return;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 预览抓取图片存放到指定路径
        /// </summary>
        /// <param name="RealPlayWnd">预览图片</param>
        /// <param name="strfileName">存放图片文件路径</param>
        /// <param name="strPosition">门岗序号</param>
        /// <param name="strDriveway">通道序号</param>
        /// <param name="ilChannel">摄像机序号</param>
        /// <returns></returns>
        public static void CaptureJPGPictureRealPlay(System.Windows.Forms.PictureBox RealPlayWnd, string strfileName, string strPosition, string strDriveway, Int32 ilChannel)
        {
            int    ilrealHandle   = RealPlay(ilChannel, RealPlayWnd);
            string strSavePicFile = GetPicFileName(strfileName, strPosition, strDriveway, ilChannel);

            CHCNetSDK.NET_DVR_CapturePicture(ilrealHandle, strSavePicFile);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 视频截图,默认BMP格式
        /// </summary>
        /// <param name="saveImageFilePath">图片格式存储全路径;eg:D:\20170913162510.jpeg</param>
        /// <param name="imageType">图片格式</param>
        /// <returns>操作结果</returns>
        public OperatedResult Capture(string saveImageFilePath, CaptureImageType imageType = CaptureImageType.BMP)
        {
            if (!IsPreviewing)
            {
                return(OperatedResult.Fail("尚未处于视频预览状态,不能进行视频截图操作."));
            }

            string _captureImageFile = string.IsNullOrEmpty(saveImageFilePath) != true ? saveImageFilePath : string.Format(@"{0}\{1}.{2}", CaptureFolders, DateTime.Now.ToString("yyyyMMddHHmmss"), imageType.ToString().ToLower());
            bool   _result           = false;

            switch (imageType)
            {
            case CaptureImageType.BMP:
                _result = CHCNetSDK.NET_DVR_CapturePicture(previewId, _captureImageFile);
                break;

            case CaptureImageType.JPEG:
                CHCNetSDK.NET_DVR_JPEGPARA _jpegParamter = new CHCNetSDK.NET_DVR_JPEGPARA();
                _jpegParamter.wPicQuality = 0;     //图像质量 Image quality
                _jpegParamter.wPicSize    = 0xff;  //抓图分辨率 Picture size: 2- 4CIF,0xff- Auto(使用当前码流分辨率),抓图分辨率需要设备支持,更多取值请参考SDK文档
                _result = CHCNetSDK.NET_DVR_CaptureJPEGPicture(UserId, CurPreviewChannelNo, ref _jpegParamter, _captureImageFile);
                break;
            }

            return(_result == true?OperatedResult.Success(_captureImageFile) : OperatedResult.Fail(LastErrorMessage));
        }
Ejemplo n.º 8
0
        public static bool Capture(string IP, int Channel, int m_lRealHandle, string cameraID)
        {
            CameraID = cameraID;
            PictureBox p = new PictureBox();

            if (!ManualRec.userIDList.ContainsKey(IP))
            {
                return(false);
            }
            int m_lUserID = ManualRec.userIDList[IP];


            //图片保存路径和文件名 the path and file name to save
            sBmpPicFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";

            //BMP抓图 Capture a BMP picture
            bool result = CHCNetSDK.NET_DVR_CapturePicture(m_lRealHandle, path + sBmpPicFileName);

            if (result)
            {
                //CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle);
                CaptureForm1 form = new CaptureForm1();
                form.Show();
                form.SetupValueEvent += Form_SetupValueEvent;
            }
            return(result);
        }
Ejemplo n.º 9
0
        private void btnBMP_Click(object sender, EventArgs e)
        {
            if (m_lRealHandle < 0)
            {
                DebugInfo("Please start live view firstly!");
                return;
            }

            string sBmpPicFileName;

            sBmpPicFileName = "test.bmp";



            if (!CHCNetSDK.NET_DVR_CapturePicture(m_lRealHandle, sBmpPicFileName))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_CapturePicture failed, error code= " + iLastErr;
                DebugInfo(str);
                return;
            }
            else
            {
                str = "NET_DVR_CapturePicture succ and the saved file is " + sBmpPicFileName;
                DebugInfo(str);
            }


            return;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 抓拍照片
        /// </summary>
        /// <param name="fileName">保存文件路径</param>
        /// <returns></returns>
        public bool CapturePicture(string fileName)
        {
            if (m_lUserID < 0 || lRealHandle < 0)
            {
                return(false);
            }

            return(CHCNetSDK.NET_DVR_CapturePicture(lRealHandle, fileName));
        }
Ejemplo n.º 11
0
 public bool CaputereBMP(string path)
 {
     //BMP抓图 Capture a BMP picture
     if (CHCNetSDK.NET_DVR_CapturePicture(m_lRealHandle, path))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 12
0
        /// <summary>
        /// 抓bmp图
        /// </summary>
        /// <param name="playHandle"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public int CapturePictureBMP(int playHandle, string fileName)
        {
            //BMP抓图 Capture a BMP picture
            if (!CHCNetSDK.NET_DVR_CapturePicture(playHandle, fileName))
            {
                uint lastErr = CHCNetSDK.NET_DVR_GetLastError();
                LogHelper.Default.Debug(string.Format("设备{0}预览抓图失败,错误代码[{1}]", playHandle, lastErr));
                return(Math.Abs((int)lastErr) * (-1));
            }

            return(0);
        }
Ejemplo n.º 13
0
        private void SavePicture()
        {
            string BMP_IMAGE = "BMP_test.bmp";

            if (CHCNetSDK.NET_DVR_CapturePicture(m_lRealHandle, BMP_IMAGE))
            {
                str = "保存路径为 " + BMP_IMAGE;
                MessageBox.Show(str);
            }
            else
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();//获取失败编码
                str      = "NET_DVR_CapturePicture failed, error code= " + iLastErr;
                MessageBox.Show(str);
                return;
            }
        }
Ejemplo n.º 14
0
        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;
        }
Ejemplo n.º 15
0
        private void btnBMP_Click(object sender, EventArgs e)
        {
            if (m_lRealHandle < 0)
            {
                DebugInfo("Please start live view firstly!"); //BMP抓图需要先打开预览
                return;
            }

            string sBmpPicFileName;

            //图片保存路径和文件名 the path and file name to save
            sBmpPicFileName = "test.bmp";

            if (comboBoxView.SelectedIndex == 0)
            {
                //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;
                    DebugInfo(str);
                    return;
                }
                else
                {
                    str = "NET_DVR_CapturePicture succ and the saved file is " + sBmpPicFileName;
                    DebugInfo(str);
                }
            }
            else
            {
                int  iWidth = 0, iHeight = 0;
                uint iActualSize = 0;

                if (!PlayCtrl.PlayM4_GetPictureSize(m_lPort, ref iWidth, ref iHeight))
                {
                    iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort);
                    str      = "PlayM4_GetPictureSize failed, error code= " + iLastErr;
                    DebugInfo(str);
                    return;
                }

                uint nBufSize = (uint)(iWidth * iHeight) * 5;

                byte[] pBitmap = new byte[nBufSize];

                if (!PlayCtrl.PlayM4_GetBMP(m_lPort, pBitmap, nBufSize, ref iActualSize))
                {
                    iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort);
                    str      = "PlayM4_GetBMP failed, error code= " + iLastErr;
                    DebugInfo(str);
                }
                else
                {
                    FileStream fs = new FileStream(sBmpPicFileName, FileMode.Create);
                    fs.Write(pBitmap, 0, (int)iActualSize);
                    fs.Close();
                    str = "PlayM4_GetBMP succ and the saved file is " + sBmpPicFileName;
                    DebugInfo(str);
                }
            }
            return;
        }
 /// <summary>
 /// captureBmp
 /// </summary>
 /// <param name="filePathName">图片保存路径和文件名</param>
 /// <param name="lChannel">通道号</param>
 /// <returns></returns>
 public static bool captureBmp(int lChannel, string filePathName)
 {
     //BMP抓图 Capture a BMP picture
     return(!CHCNetSDK.NET_DVR_CapturePicture(lChannel, filePathName));
 }
Ejemplo n.º 17
0
        /// <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;
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 预览抓取图片存放到指定路径
        /// </summary>
        /// <param name="irealHandle">预览值</param>
        /// <param name="strfileName">存放图片文件路径</param>
        /// <param name="strPosition">门岗序号</param>
        /// <param name="strDriveway">通道序号</param>
        /// <param name="ilChannel">摄像机序号</param>
        /// <returns></returns>
        public static void CaptureJPGPictureRealPlay(int irealHandle, string strfileName, string strPosition, string strDriveway, Int32 ilChannel)
        {
            string strSavePicFile = GetPicFileName(strfileName, strPosition, strDriveway, ilChannel);

            CHCNetSDK.NET_DVR_CapturePicture(irealHandle, strSavePicFile);
        }
Ejemplo n.º 19
0
 /// <summary>
 /// 保存图片,对显示图像进行瞬间抓图,只有打开图像的函数参数hWnd有效时该函数获取的参数才有效,否则无意义
 /// </summary>
 /// <param name="lRealHandle"></param>
 /// <param name="pchPicFileName"></param>
 /// <returns></returns>
 public bool CapturePicture(int lRealHandle, string pchPicFileName)
 {
     return(CHCNetSDK.NET_DVR_CapturePicture(lRealHandle, pchPicFileName));
 }