private void ProcessCapFaceData(ref CHCNetSDK.NET_DVR_CAPTURE_FACE_CFG struFaceCfg, ref bool flag)
        {
            if (0 == struFaceCfg.dwFacePicSize)
            {
                return;
            }
            string   strpath = null;
            DateTime dt      = DateTime.Now;

            strpath = string.Format("capture.jpg", Environment.CurrentDirectory);
            try
            {
                using (FileStream fs = new FileStream(strpath, FileMode.OpenOrCreate))
                {
                    int    FaceLen = struFaceCfg.dwFacePicSize;
                    byte[] by      = new byte[FaceLen];
                    Marshal.Copy(struFaceCfg.pFacePicBuffer, by, 0, FaceLen);
                    fs.Write(by, 0, FaceLen);
                    fs.Close();
                }

                pictureBoxFace.Image = Image.FromFile(strpath);
                textBoxFilePath.Text = string.Format("{0}\\{1}", Environment.CurrentDirectory, strpath);
                MessageBox.Show("Capture succeed", "SUCCESSFUL", MessageBoxButtons.OK);
            }
            catch
            {
                flag = false;
                MessageBox.Show("capature data wrong", "Error", MessageBoxButtons.OK);
            }
        }
Exemple #2
0
 public static extern int NET_DVR_GetNextRemoteConfig(int lHandle, ref CHCNetSDK.NET_DVR_CAPTURE_FACE_CFG lpOutBuff, int dwOutBuffSize);
        private void btnCapture_Click(object sender, EventArgs e)
        {
            if (m_lCapFaceCfgHandle != -1)
            {
                CHCNetSDK.NET_DVR_StopRemoteConfig(m_lCapFaceCfgHandle);
                m_lCapFaceCfgHandle = -1;
            }
            if (pictureBoxFace.Image != null)
            {
                pictureBoxFace.Image.Dispose();
                pictureBoxFace.Image = null;
            }
            textBoxFilePath.Text = "";

            CHCNetSDK.NET_DVR_CAPTURE_FACE_COND struCond = new CHCNetSDK.NET_DVR_CAPTURE_FACE_COND();
            struCond.init();
            struCond.dwSize = Marshal.SizeOf(struCond);
            int    dwInBufferSize = struCond.dwSize;
            IntPtr ptrStruCond    = Marshal.AllocHGlobal(dwInBufferSize);

            Marshal.StructureToPtr(struCond, ptrStruCond, false);
            m_lCapFaceCfgHandle = CHCNetSDK.NET_DVR_StartRemoteConfig(m_UserID, CHCNetSDK.NET_DVR_CAPTURE_FACE_INFO, ptrStruCond, dwInBufferSize, null, IntPtr.Zero);
            if (-1 == m_lCapFaceCfgHandle)
            {
                Marshal.FreeHGlobal(ptrStruCond);
                MessageBox.Show("NET_DVR_CAP_FACE_FAIL, ERROR CODE" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                return;
            }

            CHCNetSDK.NET_DVR_CAPTURE_FACE_CFG struFaceCfg = new CHCNetSDK.NET_DVR_CAPTURE_FACE_CFG();
            struFaceCfg.init();
            int  dwStatus      = 0;
            int  dwOutBuffSize = Marshal.SizeOf(struFaceCfg);
            bool Flag          = true;

            while (Flag)
            {
                dwStatus = CHCNetSDK.NET_DVR_GetNextRemoteConfig(m_lCapFaceCfgHandle, ref struFaceCfg, dwOutBuffSize);
                switch (dwStatus)
                {
                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_SUCCESS:    //成功读取到数据,处理完本次数据后需调用next
                    ProcessCapFaceData(ref struFaceCfg, ref Flag);
                    break;

                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_NEED_WAIT:
                    break;

                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_FAILED:
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lCapFaceCfgHandle);
                    MessageBox.Show("NET_SDK_GET_NEXT_STATUS_FAILED" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                    Flag = false;
                    break;

                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_FINISH:
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lCapFaceCfgHandle);
                    Flag = false;
                    break;

                default:
                    MessageBox.Show("NET_SDK_GET_STATUS_UNKOWN" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                    Flag = false;
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lCapFaceCfgHandle);
                    break;
                }
            }
            Marshal.FreeHGlobal(ptrStruCond);
        }