public ThreadProcessTianJinWeiYe(InspectConfig.ConfigData ConfigData)
 {
     //lin 20190813
     //this.strConnectString = "server=127.0.0.1;user id=root;database=spidb;Charset=utf8";//Properties.Settings.Default.MySQLConnect;
     this.strConnectString = WSClnt.PubStaticParam._strSPIdbConnectionString;
     this._configData      = ConfigData;
 }
 public ThreadProcessFov( InspectConfig.ConfigData Aconfig, string ExToFovImagePath, AppLayerLib.AppSettingHandler AappSettingHandle)
 {
     //lin 20190813
     //this.strConnectString = Properties.Settings.Default.MySQLConnect;
     this.strConnectString =  WSClnt.PubStaticParam._strSPIdbConnectionString;
     this.Aconfig = Aconfig;
     this._ExToFovImagePath = ExToFovImagePath;
     this._appSettingHandle = AappSettingHandle;
 }
Esempio n. 3
0
        public ThreadProcessCDFO(InspectConfig.ConfigData _Config)
        {
            //this.dtStartTime = dtStartTime;
            //this.dtEndTime = dtEndTime;
            //lin 20190813
            //this.strConnectString = "server=127.0.0.1;user id=root;database=spidb;Charset=utf8";//Properties.Settings.Default.MySQLConnect;
            this.strConnectString = WSClnt.PubStaticParam._strSPIdbConnectionString;
            //this.strCDPath = AstrCDPath;

            this._ConfigAl = _Config;
        }
Esempio n. 4
0
        public void SaveWholePCBImage(
            string strBarcode,
            string strDateTime,
            String strJobName,
            List <APP_SaveOrLoadImgDataInFo> AFovs,
            ref AppSettingData AappSettingData,
            ref InspectConfig.ConfigData Aconfig,
            DateTime AdtStartTime,
            string AstrPerWidthHeight,

            Basefunction _baseFuc,
            ImgCSCoreIM.ST_SaveOrLoadImgData stSave,
            string ExToFovImagePath, string ip
            )
        {
            if (AappSettingData.stDataExpVT.stSavePCBImageParams.bEnabled == false)
            {
                return;
            }

            String strPre = "SaveWholePCBImage:";
            String strMsg = SaveWholePCBImagePrivate(strBarcode, strDateTime, strJobName,
                                                     AFovs,
                                                     ref AappSettingData,

                                                     ref Aconfig, AdtStartTime, AstrPerWidthHeight, _baseFuc, stSave, ip);

            if (String.IsNullOrEmpty(strMsg) ||
                String.Equals(strMsg.ToLower().Trim(), "true"))      //Q.F.2017.04.06
            {
                strMsg = strPre + "Success!";
            }
            else
            {
                strMsg = strPre + strMsg;
            }
            strMsg += "\tOpID:" + AappSettingData.stDataExpVT.strOperatorID;
            //if (_csBaseF != null)
            //    _csBaseF.LogRecord(strMsg, false);
        }
Esempio n. 5
0
        private String SaveWholePCBImagePrivate(string strBarcode, string strDateTime, String strJobName,
                                                List <APP_SaveOrLoadImgDataInFo> AFovs,

                                                ref AppSettingData AappSettingData,
                                                ref InspectConfig.ConfigData Aconfig,
                                                DateTime AdtStartTime,
                                                string AstrPerWidthHeight,
                                                Basefunction _baseFuc,
                                                ImgCSCoreIM.ST_SaveOrLoadImgData stSave, string ip
                                                )
        {
            //String strPre = "SaveWholePCBImage:";
            String strMsg = string.Empty;

            try
            {
                if (String.IsNullOrEmpty(_strCurrentJobName) || !String.Equals(_strCurrentJobName, strJobName))
                {
                    _strCurrentJobName          = strJobName;
                    _bHasGetBoardBackGroudColor = false;
                    Array.Clear(_arrBoardBackGroudColor, 0, _arrBoardBackGroudColor.Length);
                }
                strJobName = Path.GetFileNameWithoutExtension(strJobName);
                if (AFovs == null)
                {
                    strMsg = "Fov Img is Null";
                    return(strMsg);
                }


                //if (ABrdRes.jugResult == JudgeRes.Unmeasured)
                //    return (strMsg = ABrdRes.jugResult.ToString());
                int   AiFOVWidth = 0, AiFOVHeight = 0;
                float AfPixelSizeX0um = Aconfig._pixelSizeX0, AfPixelSizeY0um = Aconfig._pixelSizeY0;
                AfPixelSizeX0um = 19.95233f; AfPixelSizeY0um = 19.9552f;
                int index     = 0;
                int iFovCount = AFovs.Count;
                unsafe
                {
                    for (index = 0; index < iFovCount; ++index)
                    {
                        if (AFovs[index].stImgData.byImgDataR == null)
                        {
                            strMsg = "Fov Img is Null";
                            return(strMsg);
                        }
                    }
                }
                String strDayTime = strDateTime;

                string strPath = AappSettingData.stDataExpVT.stSavePCBImageParams.strSaveImagePath;
                if (string.IsNullOrEmpty(strPath) == false)
                {
                    strPath = strPath + "\\" + ip;
                }
                if (_baseFuc.DirCheck(ref strPath) == -1)
                {
                    strMsg = strPath + "Could not be created;";
                    return(strMsg);
                }
                //get board barcode
                String strboardBarcode = strBarcode;
                //    AappSettingData, (byte)ABrdRes.LaneNo);//Q.F.2017.04.13
                String strTime = AdtStartTime.ToString("yyyyMMddHHmmss");
                if (string.Equals(strboardBarcode.ToUpper(), "NOREAD"))
                {
                    strboardBarcode = strTime;
                }
                string strFileName = "";
                if (AappSettingData.stDataExpVT.stSavePCBImageParams.bEnabled == true)
                {
                    switch ((EM_SavePCBImageCustomer)AappSettingData.stDataExpVT.stSavePCBImageParams.Customer)
                    {
                    case EM_SavePCBImageCustomer.HuaWei:
                    {
                        if (!string.IsNullOrEmpty(AappSettingData.stDataExpVT.stSavePCBImageParams.TaskOrder))
                        {
                            strPath = Path.Combine(strPath, AappSettingData.stDataExpVT.stSavePCBImageParams.TaskOrder);
                            if (_baseFuc.DirCheck(ref strPath) == -1)
                            {
                                strMsg = strPath + "Could not be created;";
                                return(strMsg);
                            }
                            //strPath = Path.Combine(strPath, strboardBarcode);
                            //if (_baseFuc.DirCheck(ref strPath) == -1)
                            //{
                            //    strMsg = strPath + "Could not be created;";
                            //    return strMsg;
                            //}
                        }
                        else
                        {
                            strPath = Path.Combine(strPath, strDayTime);
                            if (_baseFuc.DirCheck(ref strPath) == -1)
                            {
                                strMsg = strPath + "Could not be created;";
                                return(strMsg);
                            }
                        }
                        strFileName = strboardBarcode + PubStaticParam.RS_UnderLineSplit + strTime + PubStaticParam.RS_UnderLineSplit + strJobName;
                        strFileName = Path.Combine(strPath, strFileName);
                        break;
                    }

                    case EM_SavePCBImageCustomer.JobBarcodePerDay:
                    {
                        strPath = Path.Combine(strPath, strDayTime);
                        if (_baseFuc.DirCheck(ref strPath) == -1)
                        {
                            strMsg = strPath + "Could not be created;";
                            return(strMsg);
                        }
                        strFileName = Path.Combine(strPath, strJobName + PubStaticParam.RS_UnderLineSplit + strboardBarcode + PubStaticParam.RS_UnderLineSplit + strTime);
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    }
                }
                AiFOVWidth  = AFovs[0].stImgData.iWidth;
                AiFOVHeight = AFovs[0].stImgData.iHeight;
                int intRange     = (int)(iFovCount / _iProcessorCount) + 1;
                int lImageLength = AiFOVWidth * AiFOVHeight;
                ImgCSCoreIM.ColorFactorParams stColorFactors = AappSettingData.stColorFactorParams;

                //cal Hue for backgroud
                int hue = 0, saturation = 0, value = 0;

                Color rgb = Color.Black;
                //cal larger image size
                int WholeImageWidth = 0, WholeImageHeight = 0;

                double MinXMM = AFovs[0].fPosXmm;
                double MaxXMM = AFovs[0].fPosXmm;
                double MinYMM = AFovs[0].fPosYmm;
                double MaxYMM = AFovs[0].fPosYmm;

                for (index = 1; index < iFovCount; ++index)
                {
                    if (MinXMM > AFovs[index].fPosXmm)//correctedXmm
                    {
                        MinXMM = AFovs[index].fPosXmm;
                    }
                    if (MaxXMM < AFovs[index].fPosXmm)
                    {
                        MaxXMM = AFovs[index].fPosXmm;
                    }
                    if (MinYMM > AFovs[index].fPosYmm)//correctedYmm
                    {
                        MinYMM = AFovs[index].fPosYmm;
                    }
                    if (MaxYMM < AFovs[index].fPosYmm)
                    {
                        MaxYMM = AFovs[index].fPosYmm;
                    }
                }
                WholeImageWidth   = (int)Math.Ceiling((MaxXMM - MinXMM) * F_MM2UM / AfPixelSizeX0um);
                WholeImageHeight  = (int)Math.Ceiling((MaxYMM - MinYMM) * F_MM2UM / AfPixelSizeY0um);
                WholeImageWidth  += AiFOVWidth;
                WholeImageHeight += AiFOVHeight;
                int lLength = WholeImageWidth * WholeImageHeight;
                if (_imgByte2DR == null || _imgByte2DR.Length != lLength)
                {
                    _imgByte2DR = new byte[lLength];
                    _imgByte2DG = new byte[lLength];
                    _imgByte2DB = new byte[lLength];
                }
                Array.Clear(_imgByte2DR, 0, lLength);
                Array.Clear(_imgByte2DG, 0, lLength);
                Array.Clear(_imgByte2DB, 0, lLength);


                if (_imgByte2DRFov == null || _imgByte2DRFov.Length != lLength)
                {
                    _imgByte2DRFov = new byte[lImageLength];
                    _imgByte2DGFov = new byte[lImageLength];
                    _imgByte2DBFov = new byte[lImageLength];
                }
                Array.Clear(_imgByte2DRFov, 0, lImageLength);
                Array.Clear(_imgByte2DGFov, 0, lImageLength);
                Array.Clear(_imgByte2DBFov, 0, lImageLength);


                float  fFovWMM = AiFOVWidth * AfPixelSizeX0um * 0.001f;
                float  fFovHMM = AiFOVHeight * AfPixelSizeY0um * 0.001f;
                double LeftXMM = MinXMM; // -fFovWMM * 0.5;
                double LeftYMM = MinYMM; // -fFovHMM * 0.5;
                //for (index = 0; index < lLength; ++index)
                //{
                //    _imgByte2DG[index] = rgb.G;
                //    _imgByte2DB[index] = rgb.B;
                //    _imgByte2DB[index] = rgb.R;
                //}
                int   i = 0, j = 0;
                float fFactor    = 1.0f;
                short shColorPer = 0;
                //Parallel.ForEach(Partitioner.Create(0, iFovCount, intRange), range =>
                //{
                //for (int a = range.Item1; a < range.Item2; ++a)
                for (index = 0; index < iFovCount; ++index)
                {
                    unsafe
                    {
                        // recal rgb value
                        if (stColorFactors.byRGB2DFactorR != 100)
                        {
                            shColorPer = (short)(stColorFactors.byRGB2DFactorR * 1.28);
                            for (i = 0; i < lImageLength; ++i)
                            {
                                _imgByte2DRFov[i] = (byte)((AFovs[index].stImgData.byImgDataR[i] * shColorPer) >> 7);
                            }
                        }
                        else
                        {
                            Array.Copy(AFovs[index].stImgData.byImgDataR, _imgByte2DRFov, lImageLength);
                        }
                        if (stColorFactors.byRGB2DFactorG != 100)
                        {
                            //fFactor = stColorFactors.byRGB2DFactorR * 0.01f;
                            shColorPer = (short)(stColorFactors.byRGB2DFactorG * 1.28);
                            for (i = 0; i < lImageLength; ++i)
                            {
                                // _imgByte2DRFov[i] = (byte)(AFovs[a]._rgbImg[0][i] * fFactor);
                                _imgByte2DGFov[i] = (byte)((AFovs[index].stImgData.byImgDataG[i] * shColorPer) >> 7);
                            }
                        }
                        else
                        {
                            Array.Copy(AFovs[index].stImgData.byImgDataG, _imgByte2DGFov, lImageLength);
                        }
                        if (stColorFactors.byRGB2DFactorB != 100)
                        {
                            //fFactor = stColorFactors.byRGB2DFactorR * 0.01f;
                            shColorPer = (short)(stColorFactors.byRGB2DFactorB * 1.28);
                            for (i = 0; i < lImageLength; ++i)
                            {
                                // _imgByte2DRFov[i] = (byte)(AFovs[a]._rgbImg[0][i] * fFactor);
                                _imgByte2DBFov[i] = (byte)((AFovs[index].stImgData.byImgDataB[i] * shColorPer) >> 7);
                            }
                        }
                        else
                        {
                            Array.Copy(AFovs[index].stImgData.byImgDataB, _imgByte2DBFov, lImageLength);
                        }
                    }
                    int iShiftX = (int)Math.Ceiling((AFovs[index].fPosXmm - LeftXMM) / AfPixelSizeX0um * F_MM2UM);
                    int iShiftY = (int)Math.Ceiling((AFovs[index].fPosYmm - LeftYMM) / AfPixelSizeY0um * F_MM2UM);//Q.F.2018.01.04
                    int iStartX = 0;
                    int iStartY = 0;
                    if (iShiftX < 0)
                    {
                        iStartX = 0 - iShiftX;
                    }
                    if (iShiftY < 0)
                    {
                        iStartY = 0 - iShiftY;
                    }
                    for (i = iStartY; i < AiFOVHeight; ++i)
                    {
                        Array.Copy(_imgByte2DRFov, i * AiFOVWidth + iStartX,
                                   _imgByte2DR, (i + iShiftY) * WholeImageWidth + (0 + iShiftX),
                                   AiFOVWidth - iStartX);
                        Array.Copy(_imgByte2DGFov, i * AiFOVWidth + iStartX,
                                   _imgByte2DG, (i + iShiftY) * WholeImageWidth + (0 + iShiftX),
                                   AiFOVWidth - iStartX);
                        Array.Copy(_imgByte2DBFov, i * AiFOVWidth + iStartX,
                                   _imgByte2DB, (i + iShiftY) * WholeImageWidth + (0 + iShiftX),
                                   AiFOVWidth - iStartX);
                    }
                }
                //});

                Rectangle rect         = new Rectangle(0, 0, WholeImageWidth, WholeImageHeight);
                int       iWidthNew    = 0;
                int       iHeightNew   = 0;
                bool      bAdjustWIdth = false;
                AappSettingData.stDataExpVT.stSavePCBImageParams.byImageAdjustPercent = 30;

                if (AappSettingData.stDataExpVT.stSavePCBImageParams.byImageAdjustPercent < 100)
                {
                    bAdjustWIdth = true;
                    iWidthNew    = (int)System.Math.Ceiling(WholeImageWidth * AappSettingData.stDataExpVT.stSavePCBImageParams.byImageAdjustPercent * 0.01);
                    iHeightNew   = (int)System.Math.Ceiling(WholeImageHeight * AappSettingData.stDataExpVT.stSavePCBImageParams.byImageAdjustPercent * 0.01);
                }
                //else
                //{
                //    bAdjustWIdth = true;
                //    iWidthNew = int.Parse(AstrPerWidthHeight.Split('@')[0]);
                //    iHeightNew = int.Parse(AstrPerWidthHeight.Split('@')[1]);
                //}
                //if (string.IsNullOrEmpty(AstrPerWidthHeight) == false)
                //{
                //    bAdjustWIdth = true;
                //    iWidthNew = int.Parse(AstrPerWidthHeight.Split('@')[0]);
                //    iHeightNew = int.Parse(AstrPerWidthHeight.Split('@')[1]);
                //}
                //Q.F.2018.08.29
                AappSettingData.stDataExpVT.stSavePCBImageParams.bFillBlack = true;
                if (AappSettingData.stDataExpVT.stSavePCBImageParams.bFillBlack == true &&
                    _bHasGetBoardBackGroudColor == false)
                {
                    Array.Clear(_fParams, 0, _fParams.Length);
                    _fParams[0] = WholeImageWidth;
                    _fParams[1] = WholeImageHeight;
                    _bHasGetBoardBackGroudColor = true;
                    CvFunction.GetPcbBcgrdColor(_imgByte2DR, _imgByte2DG, _imgByte2DB, _fParams, _arrBoardBackGroudColor);
                }
                int iSaveImageMode = 1;
                //strboardBarcode = Path.GetFileNameWithoutExtension(strJobName) + "_" + strboardBarcode + "_" + strTime;
                // string strFileName = "";//Path.Combine(strPath, strboardBarcode);
                switch ((ImgCSCoreIM.EM_ImageFormat)AappSettingData.stDataExpVT.stSavePCBImageParams.ImageFormat)
                {
                case EM_ImageFormat.bmp:
                {
                    strFileName   += ".bmp";
                    iSaveImageMode = 2;
                    //resultBitMap.Save(strFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                    break;
                }

                default:
                {
                    strFileName += ".jpg";
                    if (iSaveImageMode >= 2)
                    {
                        iSaveImageMode = 1;
                    }
                    //resultBitMap.Save(strFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                    break;
                }
                }
                Bitmap resultBitMap = null;
                //Stopwatch stopWatch = new Stopwatch();
                //stopWatch.Reset();
                //stopWatch.Start();

                if (bAdjustWIdth == false)
                {
                    if (AappSettingData.stDataExpVT.stSavePCBImageParams.bFillBlack == true)
                    {
                        Array.Clear(_fParams, 0, _fParams.Length);
                        _fParams[0] = WholeImageWidth;
                        _fParams[1] = WholeImageHeight;
                        _fParams[2] = _arrBoardBackGroudColor[0];
                        _fParams[3] = _arrBoardBackGroudColor[1];
                        _fParams[4] = _arrBoardBackGroudColor[2];
                        _fParams[5] = 1;
                        byte[] imgByte2DTmp = new byte[_imgByte2DB.Length];
                        CvFunction.FillPcbBlackHole(_imgByte2DR, _imgByte2DG, _imgByte2DB,
                                                    _fParams, _imgByte2DR, _imgByte2DG, _imgByte2DB);
                    }

                    switch (iSaveImageMode)
                    {
                    case 0:
                    {
                        unsafe
                        {
                            resultBitMap = new Bitmap(WholeImageWidth, WholeImageHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                            System.Drawing.Imaging.BitmapData bmpData = resultBitMap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, resultBitMap.PixelFormat);
                            IntPtr iPtr = bmpData.Scan0;
                            int    iStride = bmpData.Stride;
                            int    iBytes = iStride * WholeImageHeight;
                            byte[] PixelValues = new byte[iBytes];
                            int    iPoint = 0;
                            int    offSet = iStride - WholeImageWidth * 3;
                            byte   byG = 0, byB = 0, byR = 0;
                            //for (i = 0; i < WholeImageHeight; ++i)
                            //{
                            //    for (j = 0; j < WholeImageWidth; ++j)
                            //    {
                            for (index = 0; index < lLength; ++index)
                            {
                                //index = i * WholeImageWidth + j;


                                byG = _imgByte2DG[index];
                                byB = _imgByte2DB[index];
                                byR = _imgByte2DR[index];


                                PixelValues[iPoint++] = byB;
                                PixelValues[iPoint++] = byG;
                                PixelValues[iPoint++] = byR;
                                // }

                                // iPoint += 3;
                                iPoint += offSet;
                            }
                            //
                            System.Runtime.InteropServices.Marshal.Copy(PixelValues, 0, iPtr, iBytes);
                            resultBitMap.UnlockBits(bmpData);
                            resultBitMap.Save(strFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                        break;
                    }

                    case 1:
                    {
                        //ImgCSCoreIM.ST_SaveOrLoadImgData stSave = new ImgCSCoreIM.ST_SaveOrLoadImgData();
                        stSave.iImgFormat = 1;
                        stSave.bUseOpcv   = false;
                        stSave.byImgDataR = _imgByte2DR;
                        stSave.byImgDataG = _imgByte2DG;
                        stSave.byImgDataB = _imgByte2DB;
                        stSave.iWidth     = WholeImageWidth;
                        stSave.iHeight    = WholeImageHeight;
                        _baseFuc.SaveImg(strFileName, stSave, 80);

                        stSave.byImgDataR = null;
                        stSave.byImgDataG = null;
                        stSave.byImgDataB = null;
                        break;
                    }

                    case 2:
                    {
                        //ImgCSCoreIM.ST_SaveOrLoadImgData stSave = new ImgCSCoreIM.ST_SaveOrLoadImgData();
                        stSave.iImgFormat = 0;
                        stSave.bUseOpcv   = true;
                        stSave.byImgDataR = _imgByte2DR;
                        stSave.byImgDataG = _imgByte2DG;
                        stSave.byImgDataB = _imgByte2DB;
                        stSave.iWidth     = WholeImageWidth;
                        stSave.iHeight    = WholeImageHeight;
                        _baseFuc.SaveImg(strFileName, stSave, 100);

                        stSave.byImgDataR = null;
                        stSave.byImgDataG = null;
                        stSave.byImgDataB = null;
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    }
                }
                else
                {
                    unsafe
                    {
                        int lImageLengthNew = iWidthNew * iHeightNew;

                        if (_imgByte2DRReSize == null || _imgByte2DRReSize.Length != lImageLengthNew)
                        {
                            _imgByte2DRReSize = new byte[lImageLengthNew];
                            _imgByte2DGReSize = new byte[lImageLengthNew];
                            _imgByte2DBReSize = new byte[lImageLengthNew];
                        }
                        Array.Clear(_imgByte2DRReSize, 0, lImageLengthNew);
                        Array.Clear(_imgByte2DGReSize, 0, lImageLengthNew);
                        Array.Clear(_imgByte2DBReSize, 0, lImageLengthNew);


                        //_imgBi[0].RGBImageScale(_imgByte2DB,
                        //             _imgByte2DG,
                        //             _imgByte2DB,
                        //             WholeImageWidth, WholeImageHeight,
                        //             r, g, b, iWidthNew, iHeightNew);
                        Array.Clear(_fParams, 0, _fParams.Length);
                        _fParams[0] = WholeImageWidth;
                        _fParams[1] = WholeImageHeight;
                        _fParams[2] = iWidthNew;
                        _fParams[3] = iHeightNew;
                        _fParams[4] = 0;
                        _baseFuc.ResizeImgByOpcv(_imgByte2DR,
                                                 _imgByte2DG,
                                                 _imgByte2DB,
                                                 _imgByte2DRReSize, _imgByte2DGReSize, _imgByte2DBReSize, _fParams);

                        AappSettingData.stDataExpVT.stSavePCBImageParams.bFillBlack = true;
                        if (AappSettingData.stDataExpVT.stSavePCBImageParams.bFillBlack == true)
                        {
                            Array.Clear(_fParams, 0, _fParams.Length);
                            _fParams[0] = iWidthNew;
                            _fParams[1] = iHeightNew;
                            _fParams[2] = _arrBoardBackGroudColor[0];
                            _fParams[3] = _arrBoardBackGroudColor[1];
                            _fParams[4] = _arrBoardBackGroudColor[2];
                            _fParams[5] = 1;
                            //byte[] imgByte2DTmp = new byte[r.Length];
                            CvFunction.FillPcbBlackHole(_imgByte2DRReSize, _imgByte2DGReSize, _imgByte2DBReSize,
                                                        _fParams, _imgByte2DRReSize, _imgByte2DGReSize, _imgByte2DBReSize);
                        }

                        rect = new Rectangle(0, 0, iWidthNew, iHeightNew);


                        switch (iSaveImageMode)
                        {
                        case 0:
                        {
                            unsafe
                            {
                                resultBitMap = new Bitmap(iWidthNew, iHeightNew, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                                //Rectangle rect = new Rectangle(0, 0, AiFOVWidth, AiFOVHeight);
                                // Rectangle rect = new Rectangle(0, 0, WholeImageWidth, WholeImageHeight);
                                System.Drawing.Imaging.BitmapData bmpData = resultBitMap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, resultBitMap.PixelFormat);
                                IntPtr iPtr = bmpData.Scan0;
                                int    iStride = bmpData.Stride;
                                int    iBytes = iStride * iHeightNew;
                                byte[] PixelValues = new byte[iBytes];
                                int    iPoint = 0;
                                int    offSet = iStride - iWidthNew * 3;
                                byte   byG = 0, byB = 0, byR = 0;

                                for (i = 0; i < iHeightNew; ++i)
                                {
                                    for (j = 0; j < iWidthNew; ++j)
                                    {
                                        index = i * iWidthNew + j;
                                        byG   = _imgByte2DGReSize[index];
                                        byB   = _imgByte2DBReSize[index];
                                        byR   = _imgByte2DRReSize[index];


                                        PixelValues[iPoint++] = byB;
                                        PixelValues[iPoint++] = byG;
                                        PixelValues[iPoint++] = byR;
                                    }

                                    // iPoint += 3;
                                    iPoint += offSet;
                                }
                                //
                                System.Runtime.InteropServices.Marshal.Copy(PixelValues, 0, iPtr, iBytes);
                                resultBitMap.UnlockBits(bmpData);
                                resultBitMap.Save(strFileName, System.Drawing.Imaging.ImageFormat.Jpeg);

                                PixelValues = null;
                            }
                            break;
                        }

                        case 1:
                        {
                            //ImgCSCoreIM.ST_SaveOrLoadImgData stSave = new ImgCSCoreIM.ST_SaveOrLoadImgData();
                            stSave.iImgFormat = 1;
                            stSave.bUseOpcv   = false;
                            stSave.byImgDataR = _imgByte2DRReSize;
                            stSave.byImgDataG = _imgByte2DGReSize;
                            stSave.byImgDataB = _imgByte2DBReSize;
                            stSave.iWidth     = iWidthNew;
                            stSave.iHeight    = iHeightNew;
                            _baseFuc.SaveImg(strFileName, stSave, 80);

                            stSave.byImgDataR = null;
                            stSave.byImgDataG = null;
                            stSave.byImgDataB = null;
                            break;
                        }

                        case 2:
                        {
                            //ImgCSCoreIM.ST_SaveOrLoadImgData stSave = new ImgCSCoreIM.ST_SaveOrLoadImgData();
                            stSave.iImgFormat = 0;
                            stSave.bUseOpcv   = true;
                            stSave.byImgDataR = _imgByte2DRReSize;
                            stSave.byImgDataG = _imgByte2DGReSize;
                            stSave.byImgDataB = _imgByte2DBReSize;
                            stSave.iWidth     = iWidthNew;
                            stSave.iHeight    = iHeightNew;
                            _baseFuc.SaveImg(strFileName, stSave, 100);

                            stSave.byImgDataR = null;
                            stSave.byImgDataG = null;
                            stSave.byImgDataB = null;

                            break;
                        }

                        default:
                        {
                            break;
                        }
                        }



                        //strboardBarcode = Path.GetFileNameWithoutExtension(strJobName) + "_" + strboardBarcode + "_" + strTime;
                        //string strFileName = Path.Combine(strPath, strboardBarcode);
                        //switch ((ImgCSCoreIM.EM_ImageFormat)AappSettingData.stDataExpVT.stSavePCBImageParams.ImageFormat)
                        //{
                        //    default:
                        //        {
                        //            strFileName += ".jpg";
                        //            resultBitMap.Save(strFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                        //            break;
                        //        }
                        //}
                    }
                }
                if (resultBitMap != null)
                {
                    resultBitMap.Dispose();
                }

                //stopWatch.Stop();
                //MessageBox.Show("iSaveImageMode:" + iSaveImageMode + "\t" + stopWatch.ElapsedMilliseconds);
            }
            catch (System.Exception ex)
            {
                //MessageBox.Show(ex.ToString());
                strMsg += ex.ToString();
                AppLogHelp.WriteError(LogFileFormate.FOVPCB, "SaveWholePCBImagePrivate " + strMsg);
            }
            finally
            {
                //_arrBoardBackGroudColor = null;

                _imgByte2DR = null;
                _imgByte2DG = null;
                _imgByte2DB = null;

                _imgByte2DRFov = null;
                _imgByte2DGFov = null;
                _imgByte2DBFov = null;

                _imgByte2DRReSize = null;
                _imgByte2DGReSize = null;
                _imgByte2DBReSize = null;
                GC.Collect();
            }

            return(strMsg);
        }
Esempio n. 6
0
        public String SaveFovImagesInfo(string strFovDataFileLoadOverByUI, string AstFirstFovPath, string strBarcode, string strDate, DateTime dtStartTime,
                                        List <APP_SaveOrLoadImgDataInFo> AFovs,
                                        ref AppSettingData AappSettingData,
                                        ref InspectConfig.ConfigData Aconfig,
                                        bool bNeedZoom, Basefunction _csBaseF,
                                        string AstrPerWidthHeight, string AtrDataExportSaveFovImagePath,
                                        ImgCSCoreIM.ST_SaveOrLoadImgData stSave,
                                        String ExToFOVImagePath, int AiCount,
                                        string strIp
                                        )
        {
            string strMsg = string.Empty;

            try
            {
                //if (ABrdRes.jugResult == JudgeRes.Unmeasured)
                //    return;

                int index     = 0;
                int iFovCount = AiCount;//AFovs.Count;
                unsafe
                {
                    //for (index = 0; index < iFovCount; ++index)
                    //{
                    //    if (AFovs[index].stImgData.byImgDataR == null)
                    //    {
                    //        strMsg = "Fov Img is Null";
                    //        return strMsg;
                    //    }
                    //}
                }
                if (iFovCount > 0)
                {
                    _csBaseF.LoadImadat(AstFirstFovPath + "\\" + 0, ref AFovs[0].stImgData);
                }
                int   AiFOVWidth = AFovs[0].stImgData.iWidth;
                int   AiFOVHeight = AFovs[0].stImgData.iHeight;
                float AfPixelSizeX0um = Aconfig._pixelSizeX0, AfPixelSizeY0um = Aconfig._pixelSizeY0;
                //AappSettingData.stDataExpVT.strSaveFovImagePath = "D:\\FOV";
                //AappSettingData.stDataExpVT.bEnSaveFovImage = true;
                if (
                    AappSettingData.stDataExpVT.bEnSaveFovImage == false)//AappSettingData.bEnDataExp == false
                {
                    strMsg = "bEnSaveFovImage is false!";
                    return(strMsg);
                }
                ////Q.F.2017.04.24
                // _csBaseF.GetSaveFovImagePath(ref ABrdRes, AstrDir, ref AappSettingData);
                if (string.IsNullOrEmpty(AappSettingData.stDataExpVT.strSaveFovImagePath))
                {
                    return("SaveFovImagePath is null!");
                }
                //string strFovImageDir = AstrDir;
                //if(!string.IsNullOrEmpty(AappSettingData.stDataExpVT.strSaveFovImagePath))
                //{
                //    strFovImageDir = AappSettingData.stDataExpVT.strSaveFovImagePath;
                //    if (_csBaseF.DirCheck(ref strFovImageDir) == -1)
                //    {
                //        strFovImageDir = AstrDir;
                //    }
                //}


                //if (_csBaseF.DirCheck(ref strFovImageDir) == -1)
                //    return;
                //get board barcode
                String strboardBarcode = strBarcode;
                bool   bUse1DImage     = false;
                if (Aconfig._VAHMsrPara_bFastMode == true && Aconfig._checkGage == false)
                {
                    bUse1DImage = true;
                }


                //save fov images
                //strFovImageDir = strFovImageDir + RS_DATAEXPORTFovImageSubDir;
                //String strFovImageDirDay = RS_EMPTY;
                String strFovImageDirPCB = string.Empty;
                if (AappSettingData.stDataExpVT.bEnSaveFovImage == true)
                {
                    //Q.F.2017.04.19
                    strFovImageDirPCB = AtrDataExportSaveFovImagePath;//// strFovImageDirDay + strboardBarcode + RS_UnderLine + ABrdRes.pcbID;
                    if (string.IsNullOrEmpty(strIp))
                    {
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(AtrDataExportSaveFovImagePath) == false)
                        {
                            string strBaseDirName = AtrDataExportSaveFovImagePath.Split(':').First();

                            string strLastDirName = AtrDataExportSaveFovImagePath.Split(':').Last();

                            strFovImageDirPCB = strBaseDirName + ":\\" + strIp + strLastDirName;
                        }
                    }
                    //strFovImageDirPCB = Path.Combine(strFovImageDirPCB, strDate + "_" + strBarcode);
                    //如果UI勾选 AappSettingData.bEnGenAOIFile
                    //if (AappSettingData.bEnGenAOIFile || AappSettingData.bEnLinkToAOIStation)
                    //{
                    //    strFovImageDirPCB = AappSettingData.stDataExpVT.strSaveFovImagePath;
                    //    if (string.IsNullOrEmpty(strFovImageDirPCB))
                    //    {
                    //        strFovImageDirPCB = Path.Combine(ExToFOVImagePath, "FOVImage");
                    //        strFovImageDirPCB = Path.Combine(strFovImageDirPCB, strboardBarcode + RS_strUnderLine + dtStartTime.ToString(RS_strTimeFormat));
                    //    }
                    //    else
                    //    {
                    //        strFovImageDirPCB = Path.Combine(strFovImageDirPCB, "FOVImage");
                    //        strFovImageDirPCB = Path.Combine(strFovImageDirPCB, strboardBarcode + RS_strUnderLine + dtStartTime.ToString(RS_strTimeFormat));
                    //    }
                    //    if (Directory.Exists(strFovImageDirPCB) == false)
                    //    {
                    //        Directory.CreateDirectory(strFovImageDirPCB);
                    //    }
                    //}
                    if (_csBaseF.DirCheck(ref strFovImageDirPCB) == -1)
                    {
                        return(strFovImageDirPCB + "Could not be created;");
                    }
                    ;
                    // _csCrImg.SaveFovImages(strFovImageDir, AFovs,AiFOVWidth,AiFOVHeight,AappSettingData);
                    //_csBaseF.LogRecord("SaveFovImage Path:" + strFovImageDirPCB, false);

                    int iProcessorCount = Environment.ProcessorCount - 1;
                    if (iProcessorCount <= 0)
                    {
                        iProcessorCount = 1;
                    }


                    int       iCount = AiCount;                         //AFovs.Count;
                    String[]  strFovComponentInfo = new String[iCount]; //Q.F.2017.06.06
                    Stopwatch stop = new Stopwatch();
                    stop.Start();

                    Rectangle rect         = new Rectangle(0, 0, AiFOVWidth, AiFOVHeight);
                    int       iWidthNew    = 0;
                    int       iHeightNew   = 0;
                    bool      bAdjustWIdth = false;
                    if (AappSettingData.stDataExpVT.byFovImageAdjustPercent < 100)
                    {
                        bAdjustWIdth = true;
                        iWidthNew    = (int)System.Math.Ceiling(AiFOVWidth * AappSettingData.stDataExpVT.byFovImageAdjustPercent * 0.01);
                        iHeightNew   = (int)System.Math.Ceiling(AiFOVHeight * AappSettingData.stDataExpVT.byFovImageAdjustPercent * 0.01);
                    }
                    else if (bNeedZoom && Aconfig._bEnGenROiCADImg == false)//Q.F.2017.08.30
                    {
                        bAdjustWIdth = true;
                        iWidthNew    = int.Parse(AstrPerWidthHeight.Split('@')[0]);
                        iHeightNew   = int.Parse(AstrPerWidthHeight.Split('@')[1]);
                    }
                    //iWidthNew = AiFOVWidth; iHeightNew = AiFOVHeight;
                    //byte[] aTmp = new byte[256];

                    int intRange = (int)(iCount / _iProcessorCount) + 1;

                    Rectangle rectNew         = new Rectangle(0, 0, iWidthNew, iHeightNew);
                    int       lImageLength    = AiFOVWidth * AiFOVHeight;
                    int       lImageLengthNew = iWidthNew * iHeightNew;
                    ImgCSCoreIM.ColorFactorParams stColorFactors = AappSettingData.stColorFactorParams;
                    bool   bGenROICADImg = Aconfig._bEnGenROiCADImg;
                    double MinXMM        = AFovs[0].fPosXmm;
                    double MaxXMM        = AFovs[0].fPosXmm;
                    double MinYMM        = AFovs[0].fPosYmm;
                    double MaxYMM        = AFovs[0].fPosYmm;

                    for (index = 1; index < iFovCount; ++index)
                    {
                        if (MinXMM > AFovs[index].fPosXmm)//correctedXmm
                        {
                            MinXMM = AFovs[index].fPosXmm;
                        }
                        if (MaxXMM < AFovs[index].fPosXmm)
                        {
                            MaxXMM = AFovs[index].fPosXmm;
                        }
                        if (MinYMM > AFovs[index].fPosYmm)//correctedYmm
                        {
                            MinYMM = AFovs[index].fPosYmm;
                        }
                        if (MaxYMM < AFovs[index].fPosYmm)
                        {
                            MaxYMM = AFovs[index].fPosYmm;
                        }
                    }


                    int lLength = AiFOVWidth * AiFOVHeight;
                    //if (_imgByte2DR == null || _imgByte2DR.Length != lLength)
                    //{
                    //    _imgByte2DR = new byte[lLength];
                    //    _imgByte2DG = new byte[lLength];
                    //    _imgByte2DB = new byte[lLength];
                    //}
                    //Array.Clear(_imgByte2DR, 0, lLength);
                    //Array.Clear(_imgByte2DG, 0, lLength);
                    //Array.Clear(_imgByte2DB, 0, lLength);

                    if (_imgByte2DRFov == null || _imgByte2DRFov.Length != lLength)
                    {
                        _imgByte2DRFov = new byte[lImageLength];
                        _imgByte2DGFov = new byte[lImageLength];
                        _imgByte2DBFov = new byte[lImageLength];
                    }
                    Array.Clear(_imgByte2DRFov, 0, lImageLength);
                    Array.Clear(_imgByte2DGFov, 0, lImageLength);
                    Array.Clear(_imgByte2DBFov, 0, lImageLength);

                    //Parallel.ForEach(Partitioner.Create(0, iCount, intRange), range =>
                    //{
                    //Parallel.ForEach(Partitioner.Create(0, iCount, (int)(iCount / _iProcessorCount) + 1), range =>
                    //{
                    //for(int iCount=0,)
                    if (_r == null || _r.Length != lLength)
                    {
                        _r = new byte[lImageLengthNew];
                        _g = new byte[lImageLengthNew];
                        _b = new byte[lImageLengthNew];
                    }
                    //for (int iIndex = range.Item1; iIndex < range.Item2; ++iIndex)
                    //{
                    for (int iIndex = 0; iIndex < iCount; ++iIndex)
                    {
                        strFovComponentInfo[iIndex] = String.Empty;
                        string strFileName = String.Empty;
                        //int iIndex = a / intRange;//a - range.Item1;
                        int    iIndexRGB   = 0;
                        string strFovImgNo = (iIndex + 1).ToString();

                        //Q.F.2017.04.19
                        //swap color
                        //int capType = AFovs[a].capType;
                        _csBaseF.LoadImadat(AstFirstFovPath + "\\" + iIndex.ToString(), ref AFovs[0].stImgData);

                        float fFactor = 1.0f;
                        int   i = 0, j = 0;
                        short shColorPer = 0;
                        unsafe
                        {
                            // recal rgb value
                            if (stColorFactors.byRGB2DFactorR != 100)
                            {
                                //fFactor = stColorFactors.byRGB2DFactorR * 0.01f;
                                shColorPer = (short)(stColorFactors.byRGB2DFactorR * 1.28);
                                for (i = 0; i < lImageLength; ++i)
                                {
                                    //R1[i] = (byte)(AFovs[a]._rgbImg[0][i] * fFactor);
                                    _imgByte2DRFov[i] = (byte)((AFovs[0].stImgData.byImgDataR[i] * shColorPer) >> 7);
                                    // R1[i] = aTmp[AFovs[a]._rgbImg[0][i]];
                                }
                            }
                            else
                            {
                                //Marshal.Copy((IntPtr)((void*)AFovs[a]._rgbImg[0]), R1, 0,
                                //   lImageLength);
                                Array.Copy(AFovs[0].stImgData.byImgDataR, _imgByte2DRFov, lImageLength);
                            }

                            if (stColorFactors.byRGB2DFactorG != 100)
                            {
                                //fFactor = stColorFactors.byRGB2DFactorR * 0.01f;
                                shColorPer = (short)(stColorFactors.byRGB2DFactorG * 1.28);
                                for (i = 0; i < lImageLength; ++i)
                                {
                                    // R1[i] = (byte)(AFovs[a]._rgbImg[0][i] * fFactor);
                                    _imgByte2DGFov[i] = (byte)((AFovs[0].stImgData.byImgDataG[i] * shColorPer) >> 7);
                                }
                            }
                            else
                            {
                                //Marshal.Copy((IntPtr)((void*)AFovs[a]._rgbImg[1]), G1, 0,
                                //   lImageLength);
                                Array.Copy(AFovs[0].stImgData.byImgDataG, _imgByte2DGFov, lImageLength);
                            }
                            if (stColorFactors.byRGB2DFactorB != 100)
                            {
                                //fFactor = stColorFactors.byRGB2DFactorR * 0.01f;
                                shColorPer = (short)(stColorFactors.byRGB2DFactorB * 1.28);
                                for (i = 0; i < lImageLength; ++i)
                                {
                                    // R1[i] = (byte)(AFovs[a]._rgbImg[0][i] * fFactor);
                                    _imgByte2DBFov[i] = (byte)((AFovs[0].stImgData.byImgDataB[i] * shColorPer) >> 7);
                                }
                            }
                            else
                            {
                                //Marshal.Copy((IntPtr)((void*)AFovs[a]._rgbImg[2]), B1, 0,
                                //   lImageLength);
                                Array.Copy(AFovs[0].stImgData.byImgDataB, _imgByte2DBFov, lImageLength);
                            }
                        }
                        int iSaveImageMode = 1;
                        if (bGenROICADImg == false)
                        {
                            if (iSaveImageMode >= 2)
                            {
                                iSaveImageMode = 1;
                            }
                            strFileName = strFovImageDirPCB + strFovImgNo + RS_DATAEXPORTImageExt;    // ".Jpeg";
                        }
                        else
                        {
                            iSaveImageMode = 2;
                            strFileName    = strFovImageDirPCB + strFovImgNo + ".bmp"; // ".Jpeg";
                        }

                        if (bAdjustWIdth == false)
                        {
                            switch (iSaveImageMode)
                            {
                            case 0:
                            {
                                unsafe
                                {
                                    Bitmap resultBitMap = new Bitmap(AiFOVWidth, AiFOVHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                                    //Rectangle rect = new Rectangle(0, 0, AiFOVWidth, AiFOVHeight);
                                    System.Drawing.Imaging.BitmapData bmpData = resultBitMap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, resultBitMap.PixelFormat);
                                    IntPtr iPtr = bmpData.Scan0;
                                    int    iStride = bmpData.Stride;
                                    int    iBytes = iStride * AiFOVHeight;
                                    byte[] PixelValues = new byte[iBytes];
                                    int    iPoint = 0;
                                    int    offSet = iStride - AiFOVWidth * 3;
                                    byte   byG = 0, byB = 0, byR = 0;
                                    short  value;
                                    //
                                    for (i = 0; i < AiFOVHeight; ++i)
                                    {
                                        for (j = 0; j < AiFOVWidth; ++j)
                                        {
                                            iIndexRGB = i * AiFOVWidth + j;
                                            //byG = AFovs[a]._rgbImg[1][iIndexRGB];
                                            //byB = AFovs[a]._rgbImg[2][iIndexRGB];
                                            //byR = AFovs[a]._rgbImg[0][iIndexRGB];
                                            byG = _imgByte2DGFov[iIndexRGB];
                                            byB = _imgByte2DBFov[iIndexRGB];
                                            byR = _imgByte2DRFov[iIndexRGB];

                                            PixelValues[iPoint++] = byB;
                                            PixelValues[iPoint++] = byG;
                                            PixelValues[iPoint++] = byR;
                                        }

                                        // iPoint += 3;
                                        iPoint += offSet;
                                    }
                                    //
                                    System.Runtime.InteropServices.Marshal.Copy(PixelValues, 0, iPtr, iBytes);
                                    resultBitMap.UnlockBits(bmpData);
                                    if (bGenROICADImg == false)            //Q.F.2017.08.30
                                    {
                                        //strFileName = strFovImageDirPCB + strFovImgNo + RS_DATAEXPORTImageExt;// ".Jpeg";
                                        resultBitMap.Save(strFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                                    }
                                    else
                                    {
                                        //strFileName = strFovImageDirPCB + strFovImgNo + ".bmp";// ".Jpeg";
                                        resultBitMap.Save(strFileName, System.Drawing.Imaging.ImageFormat.Bmp);
                                    }
                                    if (resultBitMap != null)
                                    {
                                        resultBitMap.Dispose();
                                    }
                                }
                                break;
                            }

                            case 1:
                            {
                                //ImgCSCoreIM.ST_SaveOrLoadImgData stSave = new ImgCSCoreIM.ST_SaveOrLoadImgData();
                                stSave.iImgFormat = 1;
                                stSave.bUseOpcv   = false;
                                stSave.byImgDataR = _imgByte2DRFov;
                                stSave.byImgDataG = _imgByte2DGFov;
                                stSave.byImgDataB = _imgByte2DBFov;
                                stSave.iWidth     = AiFOVWidth;
                                stSave.iHeight    = AiFOVHeight;
                                _csBaseF.SaveImg(strFileName, stSave, 100);
                                break;
                            }

                            case 2:
                            {
                                //ImgCSCoreIM.ST_SaveOrLoadImgData stSave = new ImgCSCoreIM.ST_SaveOrLoadImgData();
                                stSave.iImgFormat = 0;
                                stSave.bUseOpcv   = true;
                                stSave.byImgDataR = _imgByte2DRFov;
                                stSave.byImgDataG = _imgByte2DGFov;
                                stSave.byImgDataB = _imgByte2DBFov;
                                stSave.iWidth     = AiFOVWidth;
                                stSave.iHeight    = AiFOVHeight;
                                _csBaseF.SaveImg(strFileName, stSave, 0);
                                break;
                            }

                            default:
                                break;
                            }
                        }
                        else
                        {
                            unsafe
                            {
                                Array.Clear(_r, 0, lImageLengthNew);
                                Array.Clear(_g, 0, lImageLengthNew);
                                Array.Clear(_b, 0, lImageLengthNew);

                                Array.Clear(_fParams, 0, _fParams.Length);
                                _fParams[0] = AiFOVWidth;
                                _fParams[1] = AiFOVHeight;
                                _fParams[2] = iWidthNew;
                                _fParams[3] = iHeightNew;
                                _fParams[4] = 0;
                                _csBaseF.ResizeImgByOpcv(_imgByte2DRFov,
                                                         _imgByte2DGFov,
                                                         _imgByte2DBFov,
                                                         _r, _g, _b, _fParams);

                                switch (iSaveImageMode)
                                {
                                case 0:
                                {
                                    Bitmap resultBitMap = new Bitmap(iWidthNew, iHeightNew, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                                    //Rectangle rect = new Rectangle(0, 0, AiFOVWidth, AiFOVHeight);
                                    System.Drawing.Imaging.BitmapData bmpData = resultBitMap.LockBits(rectNew, System.Drawing.Imaging.ImageLockMode.ReadWrite, resultBitMap.PixelFormat);
                                    IntPtr iPtr = bmpData.Scan0;
                                    int    iStride = bmpData.Stride;
                                    int    iBytes = iStride * iHeightNew;
                                    byte[] PixelValues = new byte[iBytes];
                                    int    iPoint = 0;
                                    int    offSet = iStride - iWidthNew * 3;
                                    byte   byG = 0, byB = 0, byR = 0;
                                    short  value;
                                    //
                                    for (i = 0; i < iHeightNew; ++i)
                                    {
                                        for (j = 0; j < iWidthNew; ++j)
                                        {
                                            iIndexRGB = i * iWidthNew + j;
                                            byG       = _g[iIndexRGB];
                                            byB       = _b[iIndexRGB];
                                            byR       = _r[iIndexRGB];

                                            PixelValues[iPoint++] = byB;
                                            PixelValues[iPoint++] = byG;
                                            PixelValues[iPoint++] = byR;
                                        }


                                        // iPoint += 3;
                                        iPoint += offSet;
                                    }
                                    //
                                    System.Runtime.InteropServices.Marshal.Copy(PixelValues, 0, iPtr, iBytes);
                                    resultBitMap.UnlockBits(bmpData);

                                    // strFileName = strFovImageDirPCB + (a + 1).ToString() + ".Jpeg";// ".Jpeg";
                                    //strFileName = strFovImageDirPCB + strFovImgNo + RS_DATAEXPORTImageExt;// ".Jpeg";
                                    //strFileName = Path.Combine(strFovImageDirPCB,strD);
                                    resultBitMap.Save(strFileName, System.Drawing.Imaging.ImageFormat.Jpeg);

                                    if (resultBitMap != null)
                                    {
                                        resultBitMap.Dispose();
                                    }
                                    PixelValues = null;
                                    break;
                                }

                                case 1:
                                {
                                    //ImgCSCoreIM.ST_SaveOrLoadImgData stSave = new ImgCSCoreIM.ST_SaveOrLoadImgData();
                                    stSave.iImgFormat = 1;
                                    stSave.bUseOpcv   = false;
                                    stSave.byImgDataR = _r;
                                    stSave.byImgDataG = _g;
                                    stSave.byImgDataB = _b;
                                    stSave.iWidth     = iWidthNew;
                                    stSave.iHeight    = iHeightNew;
                                    if (_bmp == null || _bmp.Width * _bmp.Height != iWidthNew * iHeightNew)
                                    {
                                        if (_bmp != null && _bmp.Width * _bmp.Height != iWidthNew * iHeightNew)
                                        {
                                            _bmp.Dispose();
                                        }
                                        _bmp = new Bitmap(iWidthNew, iHeightNew, PixelFormat.Format24bppRgb);
                                    }

                                    _csBaseF.SaveImg(strFileName, stSave, 70, true, _bmp);
                                    break;
                                }

                                case 2:
                                {
                                    //ImgCSCoreIM.ST_SaveOrLoadImgData stSave = new ImgCSCoreIM.ST_SaveOrLoadImgData();
                                    stSave.iImgFormat = 0;
                                    stSave.bUseOpcv   = true;
                                    stSave.byImgDataR = _r;
                                    stSave.byImgDataG = _g;
                                    stSave.byImgDataB = _b;
                                    stSave.iWidth     = iWidthNew;
                                    stSave.iHeight    = iHeightNew;
                                    if (_bmp == null || _bmp.Width * _bmp.Height != iWidthNew * iHeightNew)
                                    {
                                        if (_bmp != null && _bmp.Width * _bmp.Height != iWidthNew * iHeightNew)
                                        {
                                            _bmp.Dispose();
                                        }
                                        _bmp = new Bitmap(iWidthNew, iHeightNew, PixelFormat.Format24bppRgb);
                                    }
                                    _csBaseF.SaveImg(strFileName, stSave, 0, true, _bmp);
                                    break;
                                }

                                default:
                                {
                                    break;
                                }
                                }
                            }
                        }
                        ////Q.F.2017.06.07
                        ////record the fov info
                        //if (AFovs[a].stFovInfo.ComponentArrayName != null)
                        //{
                        //    for (i = 0, j = AFovs[a].stFovInfo.ComponentArrayName.Length; i < j; ++i)
                        //    {
                        //        AFovs[a].stFovInfo.ComponentArrayName[a] += AFovs[a].stFovInfo.ComponentArrayName[i]
                        //            + RS_LineEnd;
                        //    }
                        //}
                    }
                    //});
                    ////Q.F.2017.06.07
                    ////record the fov info
                    //StringBuilder strFovInfo = new StringBuilder();
                    //strFovInfo.Append("COMPONENTID_ARRAYID" + ",");
                    //strFovInfo.Append("FovNo" + "\r\n");
                    //int n = 0, iLength = 0;
                    //int m = 0, iCLength = 0;
                    //for (n = 0, iLength = AFovs.Length; n < iLength; ++n)
                    //{
                    //    if (AFovs[n].stFovInfo.ComponentArrayName != null)
                    //    {
                    //        for (m = 0, iCLength = AFovs[n].stFovInfo.ComponentArrayName.Length; m < iCLength; ++m)
                    //        {
                    //            strFovInfo.Append(AFovs[n].stFovInfo.ComponentArrayName[m] + RS_SPLIT);
                    //            strFovInfo.Append((n + 1) + RS_LineEnd);
                    //        }

                    //    }
                    //}
                    //string strFileNameFovInfo = strFovImageDirPCB + strboardBarcode + RS_CSV_EXT;// ".Jpeg";
                    //FileStream fs = new FileStream(strFileNameFovInfo, FileMode.OpenOrCreate);
                    //System.IO.StreamWriter streamWrt = new StreamWriter(fs, Encoding.Default);
                    //streamWrt.Write(strFovInfo);
                    //streamWrt.Close();
                    //stop.Stop();

                    //   MessageBox.Show(stop.ElapsedMilliseconds.ToString());
                    //});

                    //copy 三点照合需要的txt.csv文件
                    //if (AappSettingData.bEnGenAOIFile == true)
                    //{
                    //    string strFile = Path.Combine(AstFirstFovPath, strBarcode + "_" + dtStartTime.ToString(RS_strTimeFormat) + ".csv");

                    //    //ToAOI
                    //    if (File.Exists(strFile))
                    //    {
                    //        File.Copy(strFile, Path.Combine(AappSettingData.stDataExpVT.strSaveFovImagePath, strBarcode + "_" + dtStartTime.ToString(RS_strTimeFormat) + ".csv"), true);
                    //        System.Threading.Thread.Sleep(300);
                    //        //File.Copy(strFile, Path.Combine(AappSettingData.stDataExpVT.strSaveFovImagePath, "FOVImage", strBarcode + "_" + dtStartTime.ToString(RS_strTimeFormat) + ".csv"), true);
                    //        //System.Threading.Thread.Sleep(100);
                    //    }
                    //    strFile = Path.Combine(AstFirstFovPath, strBarcode + "_" + dtStartTime.ToString(RS_strTimeFormat) + ".txt");
                    //    // 模拟来自FrAoi
                    //    if (File.Exists(strFile))
                    //    {
                    //        File.Copy(strFile, Path.Combine(@"D:\EYSPI\DataExport\LinkFrAOI", strBarcode + "_" + dtStartTime.ToString(RS_strTimeFormat) + ".txt"), true);
                    //        System.Threading.Thread.Sleep(100);
                    //    }
                    //}
                    if (File.Exists(strFovDataFileLoadOverByUI))
                    {
                        string strPosFile = Path.Combine(strFovImageDirPCB, Path.GetFileName(strFovDataFileLoadOverByUI));
                        File.Copy(strFovDataFileLoadOverByUI, strPosFile, true);
                    }
                }
            }
            catch (System.Exception ex)
            {
                //MessageBox.Show(ex.ToString());
                strMsg = ex.Message;
            }
            finally
            {
            }
            _imgByte2DRFov = null;
            _imgByte2DGFov = null;
            _imgByte2DBFov = null;
            _r             = null;
            _g             = null;
            _b             = null;

            return(strMsg);
        }