예제 #1
0
        /// <summary>
        /// 处理数据
        /// </summary>
        /// <param name="sIP"></param>
        /// <param name="ptrData"></param>
        public void DealData(string sIP, IntPtr ptrData, AddDeviceInfo info)
        {
            if (ptrData == IntPtr.Zero)
            {
                return;
            }

            DeviceInterface.TCData pData = (DeviceInterface.TCData)Marshal.PtrToStructure(ptrData, typeof(DeviceInterface.TCData));

            //存储数据
            string sPlate = Encoding.Default.GetString(pData.chPlate);

            sPlate = sPlate.Substring(0, sPlate.IndexOf("\0"));

            string sColor = string.Empty;

            if (sPlate == "")
            {
                sPlate = "无车牌";
            }
            else
            {
                if (info.OnReadSuccess != null)
                {
                    info.OnReadSuccess(sPlate);
                }
                if (sPlate != "无车牌")
                {
                    CarNumber = sPlate;
                }
                switch (pData.PlateColor)
                {
                case DeviceInterface.PLATE_COLOR.YELLOW_COLOR:
                    sColor = "黄";
                    break;

                case DeviceInterface.PLATE_COLOR.BLUE_COLOR:
                    sColor = "蓝";
                    break;

                case DeviceInterface.PLATE_COLOR.WHITE_COLOR:
                    sColor = "白";
                    break;

                case DeviceInterface.PLATE_COLOR.BLACK_COLOR:
                    sColor = "黑";
                    break;

                default:
                    sColor = "未知";
                    break;
                }
            }

            //if (!Directory.Exists(CaptureFilePath))
            //{
            //    Directory.CreateDirectory(CaptureFilePath);
            //}
            FileStream fs      = null;
            string     strFile = string.Empty;

            //判断图像类型
            for (int i = 0; i < pData.usImageCount; i++)
            {
                switch (pData.ImgAttrs[i].imgType)
                {
                //全景图或者二值化图
                case DeviceInterface.IMAGE_TYPE.FULL_IMAGE:
                {
                    switch (pData.ImgAttrs[i].imgFormat)
                    {
                    case DeviceInterface.IMAGE_FORMAT.IMGFORMAT_JPG:
                    {
                        if (pData.ImgAttrs[i].uiImgLen > 0)
                        {
                            strFile = CaptureFilePath;
                            fs      = new FileStream(strFile, FileMode.Create, FileAccess.Write);
                            if (fs != null)
                            {
                                byte[] bytData = new byte[pData.ImgAttrs[i].uiImgLen];
                                Marshal.Copy(pData.ImgAttrs[i].pImgData, bytData, 0, (int)pData.ImgAttrs[i].uiImgLen);
                                fs.Write(bytData, 0, (int)pData.ImgAttrs[i].uiImgLen);
                                fs.Flush();
                                fs.Close();
                            }
                        }
                    }
                    break;

                    case DeviceInterface.IMAGE_FORMAT.IMGFORMAT_BIN:
                    {
                        if (pData.ImgAttrs[i].uiImgLen > 0)
                        {
                            strFile = CaptureFilePath;
                            StringBuilder sbFile = new StringBuilder(strFile);
                            DeviceInterface.HWTC_BinaryTOBmp(sbFile, pData.ImgAttrs[i].pImgData, pData.ImgAttrs[i].usWidth,
                                                             pData.ImgAttrs[i].usHeight);
                        }
                    }
                    break;

                    default:
                        break;
                    }
                }
                break;

                //车牌图
                case DeviceInterface.IMAGE_TYPE.SPECIAL_IMAGE:
                {
                    switch (pData.ImgAttrs[i].imgFormat)
                    {
                    case DeviceInterface.IMAGE_FORMAT.IMGFORMAT_JPG:
                    {
                        if (pData.ImgAttrs[i].uiImgLen > 0)
                        {
                            strFile = CaptureFilePath;
                            fs      = new FileStream(strFile, FileMode.Create, FileAccess.Write);
                            if (fs != null)
                            {
                                byte[] bytData = new byte[pData.ImgAttrs[i].uiImgLen];
                                Marshal.Copy(pData.ImgAttrs[i].pImgData, bytData, 0, (int)pData.ImgAttrs[i].uiImgLen);
                                fs.Write(bytData, 0, (int)pData.ImgAttrs[i].uiImgLen);
                                fs.Flush();
                                fs.Close();
                            }
                        }
                    }
                    break;

                    case DeviceInterface.IMAGE_FORMAT.IMGFORMAT_BIN:
                        break;

                    default:
                        break;
                    }
                }
                break;

                default:
                    break;
                }
            }
        }