/// <summary> /// 抓拍图片,保存文件 /// </summary> /// <param name="channel">通道号</param> /// <param name="file">文件全路径</param> /// <returns>成功返回true,失败返回false</returns> public bool SaveCaptureFile(int channel, string file) { if (!this.channelHandle.ContainsKey(channel)) { return(false); } string path = Path.GetDirectoryName(file); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } bool success = true; switch (this.VideoType) { case VideoType.MvAPI: MV_IMAGEINFO bufinfo = new MV_IMAGEINFO(); try { MvAPI.MV_GetDeviceNumber(); MvAPI.MV_OpenDevice((uint)channel, true); IntPtr buf = MvAPI.MV_CaptureSingle(channel, false, 0, 0, ref bufinfo); success = MvAPI.MV_SaveFile(file, 2, buf, ref bufinfo, 1, false, true, 100, false); } catch (Exception ex) { return(false); } break; case VideoType.Sa7134Capture: try { success = Sa7134Capture.VCASaveAsJpegFile(this.channelHandle[channel], file, 100); } catch (Exception ex) { return(false); } break; } return(success); }
/// <summary> /// 抓拍图片,保存文件 /// </summary> /// <param name="channel">通道号</param> /// <param name="file">文件全路径</param> /// <returns>成功返回true,失败返回false</returns> public bool TempSaveCaptureFile(int channel, string file) { string path = Path.GetDirectoryName(file); if (!Directory.Exists(path)) Directory.CreateDirectory(path); bool success = true; switch (this.VideoType) { case VideoType.MvAPI: MV_IMAGEINFO bufinfo = new MV_IMAGEINFO(); try { MvAPI.MV_OpenDevice((uint)channel, true); IntPtr buf = MvAPI.MV_CaptureSingle(channel, false, 0, 0, ref bufinfo); success = MvAPI.MV_SaveFile(file, 2, buf, ref bufinfo, 1, false, true, 100, false); } catch (Exception ex) { return false; } break; case VideoType.Sa7134Capture: try { success = Sa7134Capture.VCASaveAsJpegFile(this.channelHandle[channel], file, 100); } catch (Exception ex) { return false; } break; } return success; }
[DllImport("MVAPI.dll", CharSet = CharSet.Auto)] // 保存文件 public static extern bool MV_SaveFile([MarshalAs(UnmanagedType.LPStr)] String FileName, int FileType, IntPtr pImageData, ref MV_IMAGEINFO pinfo, int ImageTotal, bool IsUpDown, bool ColororNot, int Quality, bool m_bRGB15);
public static extern IntPtr MV_CaptureSingle(int hDevice, bool IsProcess, int Buffer, int Bufflen, ref MV_IMAGEINFO pinfo);