Esempio n. 1
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;
        }