Пример #1
0
        //强制抓拍
        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     = ".\\image\\";
                    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 ex)
                    {
                        //AddOperLogCacheStr("保存车牌图片失败!");
                        Marshal.FreeHGlobal(struPlateResultInfo.pBuffer1);
                        Marshal.FreeHGlobal(struPlateResultInfo.pBuffer2);
                        return(-1);
                    }
                }
            }
            return(0);
        }