public override void Close() { lock (_StatusLock) { if (VideoSource != null) { InitRemoteLivePlayer2.Remote_Snapshot_Close(nHandle); InitRemoteLivePlayer2.Remote_Nvd_UnInit(nHandle); InitRemoteLivePlayer2.Remote_LivePlayer2_Close(nHandle); } this._Status = VideoStatus.Disconnected; this._IsReadyForSnapshot = false; } if (!this.TitlePanel.InvokeRequired) { this.TitlePanel.Visible = false; this.video.BackColor = Color.Navy; } }
/// <summary> /// 抓拍图片 /// </summary> /// <param name="path"></param> /// <param name="timeout">超时时间(ms)</param> /// <returns></returns> public override bool SnapShotTo(ref string path, int timeout, bool force) { bool success = false; ST_AVFrameData stAVFrameData = new ST_AVFrameData(); try { lock (_StatusLock) { //在初始化时设置超时时间了,这里就不再设置超时时间了 //int nRet = InitRemoteLivePlayer2.Remote_Snapshot_SetTimeout(nHandle, timeout); //在这里打开远程抓拍,是因为当打开远程抓拍后,如果一段时间内不进行抓拍动作,再进行抓拍时会报错 //所以在这里打开远程抓拍,并且抓拍完成后,需关闭远程抓拍 int nRet = InitRemoteLivePlayer2.Remote_Snapshot_Open(nHandle); if (nRet == 0) { ST_RemoteSnapshotParam stRemoteSnapshotParam = new ST_RemoteSnapshotParam(); //stRemoteSnapshotParam.nCameraID = this.VideoSource.Channel; //这里设置nCameraID为1,是因为IP Camera设备只有一个Camera,所以固定设为1 stRemoteSnapshotParam.nCameraID = 1; stRemoteSnapshotParam.nQuality = 5; stRemoteSnapshotParam.nPhotoFormat = 1;// PHOTOFORMAT_JPEG nRet = InitRemoteLivePlayer2.Remote_Snapshot_GetSnapshotPicture(nHandle, ref stRemoteSnapshotParam, ref stAVFrameData); if (nRet != 0) { if (Ralid.Park.BusinessModel.Configuration.AppSettings.CurrentSetting.Debug) { string logmsg = string.Format("【{0}】远程抓拍失败 ", this.VideoSource.VideoName); logmsg += " 错误代码:" + nRet; logmsg += " 错误信息:" + GetErrMessage(nRet); Ralid.GeneralLibrary.LOG.FileLog.Log("FrmSnapShoter", logmsg); } } } else { if (Ralid.Park.BusinessModel.Configuration.AppSettings.CurrentSetting.Debug) { string logmsg = string.Format("【{0}】打开远程抓拍失败 ", this.VideoSource.VideoName); logmsg += " 错误代码:" + nRet; logmsg += " 错误信息:" + GetErrMessage(nRet); Ralid.GeneralLibrary.LOG.FileLog.Log("FrmSnapShoter", logmsg); } } if (nRet == 0) { byte[] data = new byte[stAVFrameData.nDataLength]; System.Runtime.InteropServices.Marshal.Copy(stAVFrameData.pszData, data, 0, stAVFrameData.nDataLength); File.WriteAllBytes(path, data); } //关闭远程抓拍 nRet = InitRemoteLivePlayer2.Remote_Snapshot_Close(nHandle); if (nRet != 0) { if (Ralid.Park.BusinessModel.Configuration.AppSettings.CurrentSetting.Debug) { string logmsg = string.Format("【{0}】关闭远程抓拍失败 ", this.VideoSource.VideoName); logmsg += " 错误代码:" + nRet; logmsg += " 错误信息:" + GetErrMessage(nRet); Ralid.GeneralLibrary.LOG.FileLog.Log("FrmSnapShoter", logmsg); } } return(File.Exists(path)); } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } return(success); }