예제 #1
0
        private Image shotImage(int cameraID, string path)
        {
            int lChannel = iChannelNum[(int)iSelIndex]; //通道号 Channel number

            CHCNetSDK.NET_DVR_JPEGPARA lpJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA();
            lpJpegPara.wPicQuality = 0;    //图像质量 Image quality
            lpJpegPara.wPicSize    = 0xff; //抓图分辨率 Picture size: 0xff-Auto(使用当前码流分辨率)
            //抓图分辨率需要设备支持,更多取值请参考SDK文档
            //JPEG抓图保存成文件 Capture a JPEG picture
            string sJpegPicFileName;

            sJpegPicFileName = path;

            try
            {
                File.Delete(path);
            }
            catch
            {
            }
            try
            {
                CHCNetSDK.NET_DVR_CaptureJPEGPicture(cameraID, lChannel, ref lpJpegPara, sJpegPicFileName);
                return(Image.FromFile(sJpegPicFileName));
            }
            catch
            {
            }
            GC.Collect();
            GC.WaitForPendingFinalizers();

            return(null);
        }
예제 #2
0
        //JPEG抓取
        private bool Capture_JPEG(int lChannel, string sJpegPic) //通道,储存地址  如 F:
        {
            //图片保存路径和文件名 the path and file name to save
            //sJpegPicFileName = "D:\\test.jpg";
            string sJpegPicFileName;
            Random rd = new Random();

            sJpegPicFileName = sJpegPic + "\\" + lChannel + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + rd.Next(10, 100).ToString() + ".jpg";
            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))
            {
                //str = "NET_DVR_CaptureJPEGPicture failed, error code= " + CHCNetSDK.NET_DVR_GetLastError();
                //MessageBox.Show(str);
                return(false);
            }
            else
            {
                //str = "Successful to capture the JPEG file and the saved file is " + sJpegPicFileName;
                //MessageBox.Show(str);
                return(true);
            }
        }
예제 #3
0
        private void btnJPEG_Click(object sender, EventArgs e)
        {
            string sJpegPicFileName;

            //图片保存路径和文件名 the path and file name to save
            sJpegPicFileName = "JPEG_test.jpg";

            int lChannel = 1; //通道号 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;
        }
예제 #4
0
        private void btnJPEG_Click(object sender, EventArgs e)//»ñȡͼƬ
        {
            string sJpegPicFileName;
            //ͼƬ±£´æ·¾¶ºÍÎļþÃû the path and file name to save
            string time_now = DateTime.Now.ToString("yyyyMMddHHmmssffff");

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

            int lChannel = Int16.Parse(textBoxChannel.Text); //ͨµÀºÅ Channel number

            CHCNetSDK.NET_DVR_JPEGPARA lpJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA();
            lpJpegPara.wPicQuality = 1; //ͼÏñÖÊÁ¿ Image quality
            lpJpegPara.wPicSize    = 6; //ץͼ·Ö±æÂÊ Picture size: 2- 4CIF£¬0xff- Auto(ʹÓõ±Ç°ÂëÁ÷·Ö±æÂÊ)£¬×¥Í¼·Ö±æÂÊÐèÒªÉ豸֧³Ö£¬¸ü¶àÈ¡ÖµÇë²Î¿¼SDKÎĵµ

            //JPEGץͼ Capture a JPEG picture
            //CHCNetSDK.NET_DVR_CaptureJPEGPicture_NEW(m_lUserID, lChannel, ref lpJpegPara,);

            if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID[m_lUserID_flag], 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;
        }
예제 #5
0
        /*截图和录像的存放目录保存在与exe文件同文件夹下的path.txt中,在截图和录像之前先从
         * TXT中取出路径,将系统时间作为文件名。使用的是NET_DVR_CaptureJPEGPicture()和
         * NET_DVR_SaveRealData()函数*/
        private void button1_Click(object sender, EventArgs e)
        {
            CHCNetSDK.NET_DVR_JPEGPARA jpgpa = new CHCNetSDK.NET_DVR_JPEGPARA();
            jpgpa.wPicSize    = 5;
            jpgpa.wPicQuality = 2;
            DateTime time = DateTime.Now;
            folder   data = new folder();

            data.Read();
            if (data.data[0] == "" || data.data[1] == "")
            {
                Information.Text += "请先指定截图存放目录!" + System.Environment.NewLine;
                return;
            }
            string src    = data.data[0] + "/" + time.ToString("yyyy-MM-dd-hh-mm-ss") + ".jpeg";
            bool   result = CHCNetSDK.NET_DVR_CaptureJPEGPicture(Login.result, 1, ref jpgpa, src);

            if (result == false)
            {
                Information.Text += "拍照失败!" + System.Environment.NewLine;     //摄像机拍照失败
                uint nError = CHCNetSDK.NET_DVR_GetLastError();
                Information.Text += "发生错误,错误代码:" + nError + System.Environment.NewLine;
                if (nError == 34)
                {
                    Information.Text += "请检查截图存放目录!" + System.Environment.NewLine;
                }
            }
            else
            {
                Information.Text += "图片已保存到:" + src + System.Environment.NewLine;
            }
            //结束操作
        }
예제 #6
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));
        }
예제 #7
0
        private void menuCapture_Click(object sender, EventArgs e)
        {
            string sJpegPicFileName;

            //图片保存路径和文件名 the path and file name to save
            sJpegPicFileName = DateTime.Now.ToUniversalTime().ToString().Replace("/", "-").Replace(":", "-") + ".jpg";
            int lChannel = 1; //通道号 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, UserDir + sJpegPicFileName))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "发生错误, error code= " + iLastErr;
                MessageBox.Show(str);
                return;
            }
            else
            {
                str = "截图成功,文件名为: " + sJpegPicFileName + ",请打开用户文件夹查看";
                MessageBox.Show(str);
            }
            return;
        }
예제 #8
0
        private void takephoto(String filename)
        {
            string sJpegPicFileName;

            //图片保存路径和文件名 the path and file name to save
            //sJpegPicFileName = "JPEG_test.jpg";
            sJpegPicFileName = filename;
            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;
        }
예제 #9
0
        private void btnCapture_Click(object sender, EventArgs e)
        {
            CHCNetSDK.NET_DVR_JPEGPARA struJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA();
            short temp = PicQualityMap(comboBoxPicQua.SelectedItem.ToString());

            struJpegPara.wPicSize = short.Parse(textBoxPicType.Text);
            int iChanShowNum = 0;

            string path = @"C:\\SdkLog";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }


            string time       = DateTime.Now.ToString();
            string PicPath    = "C:\\SdkLog" + "\\" + "time" + ".jpg";
            IntPtr PtrPicPath = Marshal.StringToHGlobalAnsi(PicPath);

            if (CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lServerID, iChanShowNum, ref struJpegPara, PtrPicPath))
            {
                string res = "Capture success save to C:\\SdkLog";
                g_formList.AddLog(m_lServerID, AcsDemoPublic.OPERATION_SUCC_T, res);
                MessageBox.Show(res);
            }
            else
            {
                uint x = CHCNetSDK.NET_DVR_GetLastError();
                g_formList.AddLog(m_lServerID, AcsDemoPublic.OPERATION_FAIL_T, "capture Fail");
                MessageBox.Show("capture fail");
            }
            Marshal.FreeHGlobal(PtrPicPath);
        }
예제 #10
0
        public string Capture2Base64()
        {
            //图片保存路径和文件名 the path and file name to save
            string PictureFileName = Helper.UniqueFile(SaveFileType.Picture, FileExtensionType.jpg);

            int lChannel = VideoInfo.Channel; //通道号 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(loginUserId, lChannel, ref lpJpegPara, PictureFileName))
            {
                throw new Exception("[海康]截图失败:" + GetErrorMessage());
            }
            Bitmap bmp = new Bitmap(PictureFileName);

            using (MemoryStream ms1 = new MemoryStream())
            {
                bmp.Save(ms1, System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[] arr1 = new byte[ms1.Length];
                ms1.Position = 0;
                ms1.Read(arr1, 0, (int)ms1.Length);
                ms1.Close();
                return(Convert.ToBase64String(arr1));
            }
        }
예제 #11
0
        /// <summary>
        /// 捕捉当前画面
        /// </summary>
        public void CapturePic(int channelno)
        {
            if (channelno > 0)
            {
                //图片保存路径和文件名 the path and file name to save
                string sJpegPicFileName = System.AppDomain.CurrentDomain.BaseDirectory + "Picture\\";
                if (!Directory.Exists(sJpegPicFileName))
                {
                    Directory.CreateDirectory(sJpegPicFileName); //新建文件夹
                }
                sJpegPicFileName += DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";
                int lChannel = channelno;      //通道号 Channel number
                CHCNetSDK.NET_DVR_JPEGPARA lpJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA();
                lpJpegPara.wPicQuality = 0;    //图像质量 Image quality
                lpJpegPara.wPicSize    = 0x12; //抓图分辨率 Picture size: 2- 4CIF,0xff- Auto(使用当前码流分辨率),抓图分辨率需要设备支持,更多取值请参考SDK文档

                //JPEG抓图 Capture a JPEG picture
                if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, lChannel, ref lpJpegPara, sJpegPicFileName))
                {
                    uint iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    MsgBox.ShowWarn("抓图失败,错误代码" + iLastErr.ToString());
                    return;
                }
                else
                {
                    MsgBox.ShowInfo("抓图成功!");
                }
            }
        }
예제 #12
0
        public bool CaptureJpeg(string filename, out string error)
        {
            error = "";

            #region 检验状态

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

            #endregion

            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文档

            if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, VideoChannel, ref lpJpegPara, filename))
            {
                error = "抓图错误,代码为:" + CHCNetSDK.NET_DVR_GetLastError();
                return(false);
            }

            return(true);
        }
예제 #13
0
        /// <summary>
        /// 抓jpeg图
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="channel"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public int CapturePictureJPEG(string devIp, int devPort, string userName, string password, int channel, string fileName)
        {
            int userId = -1;

            DevLoginModel devLoginModel = DeviceLogin(devIp, devPort, userName, password);

            if (devLoginModel != null)
            {
                userId = devLoginModel.LoginId;
            }

            if (userId < 0)
            {
                return(-1);
            }

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

            //JPEG抓图 Capture a JPEG picture
            if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture(userId, channel, ref lpJpegPara, fileName))
            {
                uint lastErr = CHCNetSDK.NET_DVR_GetLastError();
                LogHelper.Default.Debug(string.Format("设备{0}预览抓图失败,错误代码[{1}]", userId, lastErr));
                return(Math.Abs((int)lastErr) * (-1));
            }

            return(0);
        }
예제 #14
0
        public override bool SaveImage(string nvrip, string ipcip, string filename)
        {
            NVRInfo nvr = NVRInfos.FirstOrDefault(o => o.Host.DVRIPAddress == nvrip);

            if (nvr == null)
            {
                ErrorMsg = "NVR不存在";
                _log.Error(ErrorMsg);
                return(false);
            }
            int userId = nvr.Host.LUserId;
            IPC ipc    = nvr.IPCs.FirstOrDefault(o => o.ChannelIp == ipcip);

            if (ipc == null)
            {
                ErrorMsg = "IPC不存在";
                _log.Error(ErrorMsg);
                return(false);
            }
            int channel = ipc.ChannelIndex;

            CHCNetSDK.NET_DVR_JPEGPARA jpg = new CHCNetSDK.NET_DVR_JPEGPARA()
            {
                wPicQuality = 0, wPicSize = 2
            };

            bool re = CHCNetSDK.NET_DVR_CaptureJPEGPicture(userId, channel, ref jpg, filename);

            if (!re)
            {
                _log.Error("保存图片错误" + CHCNetSDK.NET_DVR_GetLastError());
                ErrorMsg = "保存图片错误" + CHCNetSDK.NET_DVR_GetLastError();
            }
            return(re);
        }
예제 #15
0
        static public int Capture(string outfile = "capture.jpg")
        {
            Debug.WriteLine("Capture");
            if (m_lUserID < 0)
            {
                Console.WriteLine("not login, cannot capture");
                return(-1);
            }
            string sJpegPicFileName;

            //图片保存路径和文件名 the path and file name to save
            sJpegPicFileName = outfile;

            int lChannel = 1; //通道号 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();
                String str = "NET_DVR_CaptureJPEGPicture failed, error code= " + iLastErr;
                Console.WriteLine(str);
                return(-2);
            }
            else
            {
                String str = "Successful to capture the JPEG file and the saved file is " + sJpegPicFileName;
                Console.WriteLine(str);
            }
            return(0);
        }
예제 #16
0
        //抓图JPEG
        public string saveJPEG()
        {
            DateTime date = DateTime.Today;
            string   sJpegPicFileName;

            //图片保存路径和文件名 the path and file name to save
            // + "/" + UserID + "_" + date.ToString("hh:mm:ss")
            sJpegPicFileName = "D:\\" + date.ToString("yyyy-MM-dd") + ".jpg";
            int lChannel = 1; //通道号 Channel number

            CHCNetSDK.NET_DVR_JPEGPARA lpJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA();
            lpJpegPara.wPicQuality = 0;    //图像质量 Image quality 0-最好
            lpJpegPara.wPicSize    = 0xff; //抓图分辨率 Picture size: 2- 4CIF,0xff- Auto(使用当前码流分辨率),抓图分辨率需要设备支持,更多取值请参考SDK文档

            //JPEG抓图 Capture a JPEG picture
            if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture(UserID, lChannel, ref lpJpegPara, sJpegPicFileName))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_CaptureJPEGPicture failed, error code= " + iLastErr;
                MessageBox.Show(str);
                return(null);
            }
            else
            {
                str = "Successful to capture the JPEG file and the saved file is " + sJpegPicFileName;
                MessageBox.Show(str);
            }
            return(sJpegPicFileName);
        }
예제 #17
0
        private void btnJPEG_Click(object sender, EventArgs e)
        {
            int lChannel = iChannelNum[(int)iSelIndex]; //通道号 Channel number

            CHCNetSDK.NET_DVR_JPEGPARA lpJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA();
            lpJpegPara.wPicQuality = 0;    //图像质量 Image quality
            lpJpegPara.wPicSize    = 0xff; //抓图分辨率 Picture size: 0xff-Auto(使用当前码流分辨率)
            //抓图分辨率需要设备支持,更多取值请参考SDK文档

            //JPEG抓图保存成文件 Capture a JPEG picture
            string sJpegPicFileName;

            sJpegPicFileName = "filetest.jpg";//图片保存路径和文件名 the path and file name to save

            if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, lChannel, ref lpJpegPara, sJpegPicFileName))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_CaptureJPEGPicture failed, error code= " + iLastErr;
                DebugInfo(str);
                return;
            }
            else
            {
                str = "NET_DVR_CaptureJPEGPicture succ and the saved file is " + sJpegPicFileName;
                DebugInfo(str);
            }

            //JEPG抓图,数据保存在缓冲区中 Capture a JPEG picture and save in the buffer
            uint iBuffSize = 400000; //缓冲区大小需要不小于一张图片数据的大小 The buffer size should not be less than the picture size

            byte[] byJpegPicBuffer = new byte[iBuffSize];
            uint   dwSizeReturned  = 0;

            if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture_NEW(m_lUserID, lChannel, ref lpJpegPara, byJpegPicBuffer, iBuffSize, ref dwSizeReturned))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_CaptureJPEGPicture_NEW failed, error code= " + iLastErr;
                DebugInfo(str);
                return;
            }
            else
            {
                //将缓冲区里的JPEG图片数据写入文件 save the data into a file
                string     str  = "buffertest.jpg";
                FileStream fs   = new FileStream(str, FileMode.Create);
                int        iLen = (int)dwSizeReturned;
                fs.Write(byJpegPicBuffer, 0, iLen);
                fs.Close();

                //将图片显示到picturebox  dingyh
                picCapture.Image = Util.ByteToImage(byJpegPicBuffer);

                str = "NET_DVR_CaptureJPEGPicture_NEW succ and save the data in buffer to 'buffertest.jpg'.";
                DebugInfo(str);
            }

            return;
        }
예제 #18
0
        private void btnJPEG_Click(object sender, EventArgs e)
        {
            int lChannel = iChannelNum[(int)iSelIndex];

            CHCNetSDK.NET_DVR_JPEGPARA lpJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA();
            lpJpegPara.wPicQuality = 0;
            lpJpegPara.wPicSize    = 0xff;



            string sJpegPicFileName;

            sJpegPicFileName = "filetest.jpg";

            if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, lChannel, ref lpJpegPara, sJpegPicFileName))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_CaptureJPEGPicture failed, error code= " + iLastErr;
                DebugInfo(str);
                return;
            }
            else
            {
                str = "NET_DVR_CaptureJPEGPicture succ and the saved file is " + sJpegPicFileName;
                DebugInfo(str);
            }


            uint iBuffSize = 400000;

            byte[] byJpegPicBuffer = new byte[iBuffSize];
            uint   dwSizeReturned  = 0;

            if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture_NEW(m_lUserID, lChannel, ref lpJpegPara, byJpegPicBuffer, iBuffSize, ref dwSizeReturned))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_CaptureJPEGPicture_NEW failed, error code= " + iLastErr;
                DebugInfo(str);
                return;
            }
            else
            {
                string     str  = "buffertest.jpg";
                FileStream fs   = new FileStream(str, FileMode.Create);
                int        iLen = (int)dwSizeReturned;
                fs.Write(byJpegPicBuffer, 0, iLen);
                fs.Close();

                str = "NET_DVR_CaptureJPEGPicture_NEW succ and save the data in buffer to 'buffertest.jpg'.";
                DebugInfo(str);
            }

            return;
        }
예제 #19
0
파일: CameraControl.cs 프로젝트: rcw0125/-
        /// <summary>
        /// 抓图
        /// </summary>
        /// <param name="pBusiness">物流ID</param>
        /// <param name="pBusiness">业务类型</param>
        /// <returns></returns>
        public bool CapturePicture(string pLogisticsId, string pBusinessType)
        {
            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文档

            string tFileName = string.Format("{0}_{1}_{2}_{3}.jpg", pLogisticsId, pBusinessType, _cameraCfg.Position, DateTime.Now.ToString("HHmmss"));

            //return CHCNetSDK.NET_DVR_CaptureJPEGPicture(_userID, int.Parse(_cameraCfg.Channel), ref lpJpegPara, _curPhotoConfig.PictureSavePath + tFileName);
            return(CHCNetSDK.NET_DVR_CaptureJPEGPicture(_userID, 1, ref lpJpegPara, _curPhotoConfig.PictureSavePath + tFileName));
        }
예제 #20
0
        /// <summary>
        /// 抓取图片存放到指定路径
        /// </summary>
        /// <param name="strfileName">存放图片文件路径</param>
        /// <param name="strPosition">门岗序号</param>
        /// <param name="strDriveway">通道序号</param>
        /// <param name="ilChannel">摄像机序号</param>
        /// <returns></returns>
        public static void CaptureJPEGPicture(string strfileName, string strPosition, string strDriveway, Int32 ilChannel)
        {
            string strSavePicFile = GetPicFileName(strfileName, strPosition, strDriveway, ilChannel);

            CHCNetSDK.NET_DVR_JPEGPARA jpegpara = new CHCNetSDK.NET_DVR_JPEGPARA
            {
                wPicQuality = 0, //图像质量
                wPicSize    = 0  //图像大小
            };
            CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, ilChannel, ref jpegpara, strSavePicFile);
            //  CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, ilChannel,ref jpegpara, strSavePicFile);
        }
예제 #21
0
        public bool CaputereJPEG(string path)
        {
            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, CurrentChannel, ref lpJpegPara, path))
            {
                return(true);
            }
            return(false);
        }
예제 #22
0
        /// <summary>
        /// JPEG抓拍照片
        /// </summary>
        /// <param name="fileName">保存文件路径</param>
        /// <returns></returns>
        public bool CapturePictureJPEG(string fileName)
        {
            if (m_lUserID < 0 || lRealHandle < 0)
            {
                return(false);
            }

            CHCNetSDK.NET_DVR_JPEGPARA lpJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA();
            lpJpegPara.wPicQuality = 1;    //图片质量系数:0-最好,1-较好,2-一般
            lpJpegPara.wPicSize    = 0xff; //抓图分辨率 Picture size: 2- 4CIF,0xff- Auto(使用当前码流分辨率),抓图分辨率需要设备支持,更多取值请参考SDK文档

            //JPEG抓图 Capture a JPEG picture
            return(CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, c_channel, ref lpJpegPara, fileName));
        }
예제 #23
0
        private void CaptureJpeg()
        {
            int lChannel = Int32.Parse(dvrControl.dvrObject.Channel);

            CHCNetSDK.NET_DVR_JPEGPARA lpJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA();


            lpJpegPara.wPicQuality = captureController.captureSettingModel.PictureQuality;
            lpJpegPara.wPicSize    = captureController.captureSettingModel.PictureSize;

            //Capture a JPEG picture
            string sJpegPicFileName;

            sJpegPicFileName = "reza.jpeg";

            if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, lChannel, ref lpJpegPara, sJpegPicFileName))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_CaptureJPEGPicture failed, error code= " + iLastErr;
                //DebugInfo(str);
                MessageControl messageControl = new MessageControl("Capture error", str);
                messageControl.ShowDialog();
                return;
            }
            else
            {
                str = "NET_DVR_CaptureJPEGPicture succ and the saved file is " + sJpegPicFileName;
                //DebugInfo(str);
            }

            byJpegPicBuffer = new byte[iBuffSize];


            if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture_NEW(m_lUserID, lChannel, ref lpJpegPara, byJpegPicBuffer, iBuffSize, ref dwSizeReturned))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_CaptureJPEGPicture_NEW failed, error code= " + iLastErr;
                //DebugInfo(str);
                MessageControl messageControl = new MessageControl("Capture error", str);
                messageControl.ShowDialog();
                return;
            }
            else
            {
                str = "NET_DVR_CaptureJPEGPicture_NEW succ and save the data in buffer to 'buffertest.jpg'.";
            }

            return;
        }
예제 #24
0
        public string[] picture(string zhakou, string num, int m_lUserID, string ip, string path, string cameraip)
        {
            string[] pic    = new string[2];
            string   date   = DateTime.Now.ToString("yyyy-MM-dd");
            string   sPath1 = @path + "\\" + date + "\\" + cameraip.ToString() + "\\" + num.ToString() + "\\";
            string   sPath2 = @"ftp://" + ip + "/" + date + "/" + cameraip.ToString() + "/" + num.ToString() + "/";

            try
            {
                if (!Directory.Exists(sPath1))
                {
                    Directory.CreateDirectory(sPath1);
                }
            }
            catch (Exception ex)
            {
                loginfo.Error(ex);
            }
            DateTime time          = DateTime.Now;
            bool     result        = false;
            string   sPicFileName  = sPath1 + time.ToString("yyyyMMddHHmmssfff");
            string   sPicFileName2 = sPath2 + time.ToString("yyyyMMddHHmmssfff");

            CHCNetSDK.NET_DVR_JPEGPARA para = new CHCNetSDK.NET_DVR_JPEGPARA();
            para.wPicSize = 0xff;

            para.wPicQuality = 0;
            result           = CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, 1, ref para, sPicFileName + ".jpg");
            uint iLastErr = CHCNetSDK.NET_DVR_GetLastError();

            if (iLastErr != 0)
            {
                loginfo.Error(zhakou + "第" + num.ToString() + "道摄像头拍照错误信息:" + iLastErr.ToString());

                pic[0] = sPicFileName2 + ".jpg";
                pic[1] = sPicFileName + ".jpg";
            }
            if (iLastErr == 0)
            {
                loginfo.Info(zhakou + "第" + num.ToString() + "道摄像头拍照成功");
                pic[0] = sPicFileName2 + ".jpg";
                pic[1] = sPicFileName + ".jpg";
            }
            return(pic);
        }
        /// <summary>
        /// captureJpeg
        /// </summary>
        /// <param name="filePathName">图片保存路径和文件名</param>
        /// <param name="currCameraId">登陆的摄像头序号</param>
        /// <param name="filePathName">通道号</param>
        public static bool CaptureJpeg(string filePathName, int currCameraId, int lChannel)
        {
            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
            try
            {
                CHCNetSDK.NET_DVR_CaptureJPEGPicture(currCameraId, lChannel, ref lpJpegPara, filePathName);
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(filePathName + " 抓图失败:" + e.Message);
                return(false);
            }
        }
예제 #26
0
        public string Capture2Image()
        {
            //图片保存路径和文件名 the path and file name to save
            string PictureFileName = Helper.UniqueFile(SaveFileType.Picture, FileExtensionType.jpg);

            int lChannel = VideoInfo.Channel; //通道号 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(loginUserId, lChannel, ref lpJpegPara, PictureFileName))
            {
                throw new Exception("[海康]截图失败:" + GetErrorMessage());
            }
            return(PictureFileName);
        }
예제 #27
0
        private void btnPic_Click(object sender, EventArgs e)
        {
            //开始截图,图片质量
            CHCNetSDK.NET_DVR_JPEGPARA lpPreviewInfo = new CHCNetSDK.NET_DVR_JPEGPARA();
            lpPreviewInfo.wPicQuality = 0;
            lpPreviewInfo.wPicSize    = 19;

            if (CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, 36, ref lpPreviewInfo, @"C:\Users\EMEWE\Desktop\1.jpg"))
            {
                picImg.Image = Image.FromFile(@"C:\Users\EMEWE\Desktop\1.jpg");
            }
            else
            {
                MessageBox.Show(CHCNetSDK.NET_DVR_GetLastError().ToString());
            }
            btnPic.Enabled       = false;
            btnCancelPic.Enabled = true;
        }
예제 #28
0
        /// <summary>
        /// 保存JEPG图片
        /// </summary>
        public bool SaveJEPG(string sJpegPicFileName)
        {
            bool ret      = false;
            int  lChannel = iChannelNum[(int)iSelIndex]; //通道号 Channel number

            CHCNetSDK.NET_DVR_JPEGPARA lpJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA();
            lpJpegPara.wPicQuality = 0;    //图像质量 Image quality
            lpJpegPara.wPicSize    = 0xff; //抓图分辨率 Picture size: 0xff-Auto(使用当前码流分辨率)
            //抓图分辨率需要设备支持,更多取值请参考SDK文档

            //JPEG抓图保存成文件 Capture a JPEG picture
            if (CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, lChannel, ref lpJpegPara, sJpegPicFileName))
            {
                ret = true;
            }
            else
            {
                m_lastErr = CHCNetSDK.NET_DVR_GetLastError();
            }

            ////JEPG抓图,数据保存在缓冲区中 Capture a JPEG picture and save in the buffer
            //uint iBuffSize = 400000; //缓冲区大小需要不小于一张图片数据的大小 The buffer size should not be less than the picture size
            //byte[] byJpegPicBuffer = new byte[iBuffSize];
            //uint dwSizeReturned = 0;

            //if (CHCNetSDK.NET_DVR_CaptureJPEGPicture_NEW(m_lUserID, lChannel, ref lpJpegPara, byJpegPicBuffer, iBuffSize, ref dwSizeReturned))
            //{
            //    //将缓冲区里的JPEG图片数据写入文件 save the data into a file
            //    string str = "buffertest.jpg";
            //    FileStream fs = new FileStream(str, FileMode.Create);
            //    int iLen = (int)dwSizeReturned;
            //    fs.Write(byJpegPicBuffer, 0, iLen);
            //    fs.Close();
            //    ret = true;
            //}
            //else
            //{
            //    m_lastErr = CHCNetSDK.NET_DVR_GetLastError();
            //}

            return(ret);
        }
        /// <summary>
        /// 拍照
        /// </summary>
        /// <param name="strfileName">名称</param>
        /// <param name="id">编号</param>
        /// <param name="ilChannel">路数</param>
        /// <returns></returns>
        public static string CaptureJPEGPicture(string strfileName, int id, int ilChannel)
        {
            string strSavePicFile = GetPicFileName(id, strfileName, ilChannel);

            CHCNetSDK.NET_DVR_JPEGPARA jpegpara = new CHCNetSDK.NET_DVR_JPEGPARA
            {
                wPicQuality = 0, //图像质量
                wPicSize    = 0  //图像大小
            };
            bool result = CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, ilChannel, ref jpegpara, strSavePicFile);

            if (result)
            {
                return(strSavePicFile);
            }
            else
            {
                return("");
            }
        }
예제 #30
0
        public override void CapturePic()
        {
            try
            {
                if (CurVideo != null)
                {
                    int lChannel = CurVideo.ChannelNo;  //通道号
                    //图片保存路径和文件名 the path and file name to save
                    string sJpegPicFileName = System.AppDomain.CurrentDomain.BaseDirectory + "Picture\\";
                    if (!Directory.Exists(sJpegPicFileName))
                    {
                        Directory.CreateDirectory(sJpegPicFileName); //新建文件夹
                    }
                    sJpegPicFileName += DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";
                    CHCNetSDK.NET_DVR_JPEGPARA lpJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA();
                    lpJpegPara.wPicQuality = 0;    //图像质量 Image quality
                    lpJpegPara.wPicSize    = 0x12; //抓图分辨率 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();
                        MsgBox.ShowWarn("通道" + "抓图失败,错误代码" + iLastErr.ToString());
                        return;
                    }
                    else
                    {
                        MsgBox.ShowInfo("通道" + "抓图成功!");
                    }
                }
                else
                {
                    MsgBox.ShowWarn("请选择需要抓图的通道号!");
                }
            }
            catch (Exception ex)
            { }
            return;
        }