public void DeviceManualSpan(DeviceInfo deviceInfo) { if (DeviceIsNull(deviceInfo)) { return; } //不在抓拍时间范围内,不需要发送手动抓拍命令 if (deviceInfo.beginTime != DateTime.MinValue) { if (DateTime.Now < deviceInfo.beginTime || DateTime.Now > deviceInfo.endTime) { return; } } //先预览,再抓拍!关闭预览 CHCNetSDK.NET_DVR_MANUALSNAP strucManualsnap = new CHCNetSDK.NET_DVR_MANUALSNAP(); CHCNetSDK.NET_DVR_PLATE_RESULT struPlateResult = new CHCNetSDK.NET_DVR_PLATE_RESULT(); struPlateResult.pBuffer1 = Marshal.AllocHGlobal(2 * 1024 * 1024); struPlateResult.pBuffer2 = Marshal.AllocHGlobal(2 * 1024 * 1024); if (CHCNetSDK.NET_DVR_ManualSnap(deviceInfo.DVRLoginID, ref strucManualsnap, ref struPlateResult)) { if (OnShowInfoData != null) { OnShowInfoData(InfoType.设备信息, deviceInfo, "手动抓拍成功!"); } } else { if (OnShowInfoData != null) { OnShowInfoData(InfoType.设备信息, deviceInfo, "手动抓拍失败,错误原因:" + CHCNetSDK.NET_DVR_GetLastError().ToString()); } deviceInfo.State = DeviceInfo.DeviceState.重启状态; } }
//强制抓拍 public int camera_ForceGetBigImage() { CHCNetSDK.NET_DVR_PLATE_RESULT struPlateResultInfo = new CHCNetSDK.NET_DVR_PLATE_RESULT(); struPlateResultInfo.pBuffer1 = Marshal.AllocHGlobal(2 * 1024 * 1024); struPlateResultInfo.pBuffer2 = Marshal.AllocHGlobal(1024 * 1024); CHCNetSDK.NET_DVR_MANUALSNAP struInter = new CHCNetSDK.NET_DVR_MANUALSNAP(); struInter.byLaneNo = 1; if (!CHCNetSDK.NET_DVR_ManualSnap(m_lUserID, ref struInter, ref struPlateResultInfo)) { uint iLastErr = CHCNetSDK.NET_DVR_GetLastError(); string strErr = "NET_DVR_ManualSnap failed, error code= " + iLastErr; MF.AddOperLogCacheStr(strErr); Marshal.FreeHGlobal(struPlateResultInfo.pBuffer1); Marshal.FreeHGlobal(struPlateResultInfo.pBuffer2); return(-1); } else { int iLen = (int)struPlateResultInfo.dwPicLen;; if (iLen > 0) { byte[] by = new byte[iLen]; if (struPlateResultInfo.struPlateInfo.sLicense.Equals("无车牌")) { GetPlateNo = "未检测"; } else { string temp = ""; switch (struPlateResultInfo.struPlateInfo.byColor) { case 0: temp = "蓝"; break; case 1: temp = "黄"; break; case 2: temp = "白"; break; case 3: temp = "黑"; break; case 4: temp = "绿"; break; default: break; } GetPlateNo = struPlateResultInfo.struPlateInfo.sLicense; } GetVehicleLogoRecog = ""; GetVehicleLogoRecog = CHCNetSDK.VLR_VEHICLE_CLASS[struPlateResultInfo.struVehicleInfo.byVehicleLogoRecog]; FlieClass fc = new FlieClass(); string dirpath = GlobalMember.SavePicPath + "\\"; DateTime forcetimedt = DateTime.Now; string forcetime = forcetimedt.ToString("yyyyMMddHHmmss"); string imagename = forcetime + GetPlateNo + ".bmp"; dirpath += DateTime.Now.Year.ToString(); dirpath += "年\\"; dirpath += DateTime.Now.Month.ToString(); dirpath += "月\\"; dirpath += DateTime.Now.Day.ToString(); dirpath += "日\\"; imagepath = dirpath + imagename; Marshal.Copy(struPlateResultInfo.pBuffer1, by, 0, iLen); try { if (true == fc.WriteFileImage(dirpath, imagename, by, 0, iLen)) { Marshal.FreeHGlobal(struPlateResultInfo.pBuffer1); Marshal.FreeHGlobal(struPlateResultInfo.pBuffer2); return(0); } else { Marshal.FreeHGlobal(struPlateResultInfo.pBuffer1); Marshal.FreeHGlobal(struPlateResultInfo.pBuffer2); //AddOperLogCacheStr("保存车牌图片失败!"); return(-1); } } catch (Exception) { //AddOperLogCacheStr("保存车牌图片失败!"); Marshal.FreeHGlobal(struPlateResultInfo.pBuffer1); Marshal.FreeHGlobal(struPlateResultInfo.pBuffer2); return(-1); } } } return(0); }