/**************************************************************************** * @fn SaveImage * @brief 保存图片 * @param pSaveParam IN 保存图片配置参数结构体 * @return 成功:0;错误:-1 ****************************************************************************/ public int SaveImage(ref MyCamera.MV_SAVE_IMAGE_PARAM pSaveParam) { int nRet; nRet = m_pCSI.MV_CC_SaveImage_NET(ref pSaveParam); if (MyCamera.MV_OK != nRet) { return(CO_FAIL); } return(CO_OK); }
//回调函数 private void SaveImageCallBack(IntPtr pData, ref MyCamera.MV_FRAME_OUT_INFO pFrameInfo, IntPtr pUser) { DateTime dataTime1 = DateTime.Now; if ((3 * pFrameInfo.nFrameLen + 2048) > m_nBufSizeForSaveImage) { m_nBufSizeForSaveImage = 3 * pFrameInfo.nFrameLen + 2048; m_pBufForSaveImage = new byte[m_nBufSizeForSaveImage]; } IntPtr pImage = Marshal.UnsafeAddrOfPinnedArrayElement(m_pBufForSaveImage, 0); MyCamera.MV_SAVE_IMAGE_PARAM stSaveParam = new MyCamera.MV_SAVE_IMAGE_PARAM(); stSaveParam.enImageType = MyCamera.MV_SAVE_IAMGE_TYPE.MV_Image_Bmp; stSaveParam.enPixelType = pFrameInfo.enPixelType; stSaveParam.pData = pData; stSaveParam.nDataLen = pFrameInfo.nFrameLen; stSaveParam.nHeight = pFrameInfo.nHeight; stSaveParam.nWidth = pFrameInfo.nWidth; stSaveParam.pImageBuffer = pImage; stSaveParam.nBufferSize = m_nBufSizeForSaveImage; stSaveParam.nImageLen = 0; int nRet = m_pOperator.SaveImage(ref stSaveParam); MemoryStream ms = new MemoryStream(); //新建内存流 ms.Write(m_pBufForSaveImage, 0, (int)stSaveParam.nImageLen); //附值 this.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart) delegate() { image_Camera.Source = imageSourceConverter.ConvertFrom(ms) as BitmapFrame; GC.Collect(); //强制回收资源 } ); Thread.Sleep(500); //这个延时可以让UI的响应更为流畅,但是图片的刷新较慢,打印的事件lTime在40ms内 }