Пример #1
0
        public void SetAppSettingAsync(AppSettingData entity, Action <ResponseBase, Exception> callback)
        {
            DataRequest <AppSettingData> request = new DataRequest <AppSettingData>()
            {
                Data = entity
            };

            RpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IAppSettingController.SetAppSetting), data: request, callback);
        }
            public void SetAppSettingAsync(AppSettingData entity, Action <ResponseBase, Exception> callback)
            {
                DataRequest <AppSettingData> request = new DataRequest <AppSettingData>()
                {
                    Data = entity
                };

                PostAsync(SControllerName, nameof(IAppSettingController.SetAppSetting), request.ToQuery(SingleUser.LoginName, SingleUser.PasswordSha1), request, callback);
            }
Пример #3
0
 public ComboBoxSetting(AppSettingData <int> data)
 {
     this.InitializeComponent();
     if (data == null)
     {
         throw new ArgumentNullException("AppSettingData must not be null");
     }
     this.DataContext = data;
 }
        private void SetServerChannelTimeStamp(DateTime timestamp)
        {
            AppSettingData appSettingData = new AppSettingData()
            {
                Key   = NTKeyword.ServerChannelTimestampAppSettingKey,
                Value = timestamp
            };

            VirtualRoot.Execute(new SetLocalAppSettingCommand(appSettingData));
        }
Пример #5
0
 public DataResponse <List <AppSettingData> > AppSettings([FromBody] AppSettingsRequest request)
 {
     try {
         var data = HostRoot.Instance.AppSettingSet;
         return(DataResponse <List <AppSettingData> > .Ok(data.Select(a => AppSettingData.Create(a)).ToList()));
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError <DataResponse <List <AppSettingData> > >(e.Message));
     }
 }
Пример #6
0
 public void Update()
 {
     if (ModuleConfig.StorageType == StorageType.MySql)
     {
         CreateMySqlTableIfNotExists();
         var query = @"UPDATE `tmodule_app_settings` SET `settings_value` = '" + Value + "' WHERE `tmodule_app_settings`.`settings_name` = '" + Name + "'";
         Query.ExecuteMySql(query);
         GetID();
         AppSettingData.UpdateAppSetting(this);
     }
 }
Пример #7
0
        private void SetServerJsonVersion(string serverJsonVersion)
        {
            AppSettingData appSettingData = new AppSettingData()
            {
                Key   = NTKeyword.ServerJsonVersionAppSettingKey,
                Value = serverJsonVersion
            };
            string oldVersion = GetServerJsonVersion();

            VirtualRoot.Execute(new SetLocalAppSettingCommand(appSettingData));
            VirtualRoot.RaiseEvent(new ServerJsonVersionChangedEvent(oldVersion, serverJsonVersion));
        }
Пример #8
0
        private void SetServerJsonVersion(string serverJsonVersion)
        {
            AppSettingData appSettingData = new AppSettingData()
            {
                Key   = "ServerJsonVersion",
                Value = serverJsonVersion
            };
            string oldVersion = GetServerJsonVersion();

            VirtualRoot.Execute(new ChangeLocalAppSettingCommand(appSettingData));
            VirtualRoot.Happened(new ServerJsonVersionChangedEvent(oldVersion, serverJsonVersion));
        }
Пример #9
0
 public EthNoDevFeeEditViewModel()
 {
     _ethNoDevFeeWallet = GetEthNoDevFeeWallet();
     this.Save          = new DelegateCommand(() => {
         AppSettingData appSettingData = new AppSettingData()
         {
             Key   = nameof(EthNoDevFeeWallet),
             Value = EthNoDevFeeWallet
         };
         VirtualRoot.Execute(new SetLocalAppSettingCommand(appSettingData));
         VirtualRoot.Execute(new CloseWindowCommand(this.Id));
     });
 }
Пример #10
0
        private static void SetUseDevices(IGpuSet gpuSet, List <int> gpuIndexes)
        {
            if (gpuIndexes.Count != 0 && gpuIndexes.Count == gpuSet.Count)
            {
                gpuIndexes = new List <int>();
            }
            AppSettingData appSettingData = new AppSettingData()
            {
                Key   = "UseDevices",
                Value = string.Join(",", gpuIndexes)// 存逗号分隔的字符串,因为litedb处理List、Array有问题
            };

            VirtualRoot.Execute(new ChangeLocalAppSettingCommand(appSettingData));
        }
Пример #11
0
        private static SettingSection BuildShootingSection()
        {
            var section = new SettingSection(SystemUtil.GetStringResource("SettingSection_Image"));

            section.Add(new ToggleSetting(
                            new AppSettingData <bool>(SystemUtil.GetStringResource("PostviewTransferSetting"), SystemUtil.GetStringResource("Guide_ReceiveCapturedImage"),
                                                      () => { return(ApplicationSettings.GetInstance().IsPostviewTransferEnabled); },
                                                      enabled => { ApplicationSettings.GetInstance().IsPostviewTransferEnabled = enabled; })));

            var limited = (Application.Current as App).IsFunctionLimited;

            var geoGuide = limited ? "TrialMessage" : "AddGeotag_guide";
            AppSettingData <bool> geoSetting = null;

            geoSetting = new AppSettingData <bool>(SystemUtil.GetStringResource("AddGeotag"), SystemUtil.GetStringResource(geoGuide),
                                                   () =>
            {
                if (limited)
                {
                    return(false);
                }
                else
                {
                    return(ApplicationSettings.GetInstance().GeotagEnabled);
                }
            },
                                                   enabled =>
            {
                ApplicationSettings.GetInstance().GeotagEnabled = enabled;
                if (enabled)
                {
                    RequestPermission(geoSetting);
                }
            });
            var geoToggle = new ToggleSetting(geoSetting);

            if (ApplicationSettings.GetInstance().GeotagEnabled)
            {
                RequestPermission(geoSetting);
            }

            if (limited)
            {
                ApplicationSettings.GetInstance().GeotagEnabled = false;
                geoSetting.IsActive = false;
            }
            section.Add(geoToggle);

            return(section);
        }
Пример #12
0
 public DataResponse <AppSettingData> AppSetting([FromBody] AppSettingRequest request)
 {
     try {
         if (!VirtualRoot.LocalAppSettingSet.TryGetAppSetting(request.Key, out IAppSetting data))
         {
             data = null;
         }
         return(DataResponse <AppSettingData> .Ok(AppSettingData.Create(data)));
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError <DataResponse <AppSettingData> >(e.Message));
     }
 }
Пример #13
0
 public void Insert()
 {
     if (ModuleConfig.StorageType == StorageType.MySql)
     {
         CreateMySqlTableIfNotExists();
         GetID();
         if (!AppSettingList.Instance.Exists(Name))
         {
             var query = @"INSERT INTO `tmodule_app_settings` (`settings_name`, `settings_value`) VALUES ('" + Name + "', '" + Value + "');";
             Query.ExecuteMySql(query);
             GetID();
             AppSettingData.AddAppSetting(this);
         }
     }
 }
Пример #14
0
        private static void SetUseDevices(IGpuSet gpuSet, List <int> gpuIndexes)
        {
            // 全选等于全不选,所以存储空值就可以了,而且可以避免新插显卡问题
            if (gpuIndexes.Count != 0 && gpuIndexes.Count == gpuSet.Count)
            {
                gpuIndexes = new List <int>();
            }
            AppSettingData appSettingData = new AppSettingData()
            {
                Key   = NTKeyword.UseDevicesAppSettingKey,
                Value = string.Join(",", gpuIndexes)// 存逗号分隔的字符串,因为litedb处理List、Array有问题
            };

            VirtualRoot.Execute(new SetLocalAppSettingCommand(appSettingData));
        }
Пример #15
0
        private void AddToDataGridView(AppSettingData data)
        {
            try
            {
                int nNewRow = dataGridView1.Rows.Add();

                dataGridView1.Rows[nNewRow].Cells[0].Value      = data.m_setting;
                dataGridView1.Rows[nNewRow].Cells[0].ReadOnly   = true;
                dataGridView1.Rows[nNewRow].Cells[0].Style.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold);

                dataGridView1.Rows[nNewRow].Cells[1].Value = data.m_value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #16
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);
        }
Пример #17
0
 public LocalAppSettingSet(string dbFileFullName)
 {
     _dbFileFullName = dbFileFullName;
     VirtualRoot.BuildCmdPath <SetLocalAppSettingCommand>(path: message => {
         if (message.AppSetting == null)
         {
             return;
         }
         if (_dicByKey.TryGetValue(message.AppSetting.Key, out AppSettingData entity))
         {
             entity.Value = message.AppSetting.Value;
         }
         else
         {
             entity = AppSettingData.Create(message.AppSetting);
             _dicByKey[message.AppSetting.Key] = entity;
         }
         using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) {
             var col = db.GetCollection <AppSettingData>();
             col.Upsert(entity);
         }
         VirtualRoot.RaiseEvent(new LocalAppSettingChangedEvent(message.MessageId, entity));
     }, location: this.GetType());
 }
Пример #18
0
        private static SettingSection BuildDisplaySection()
        {
            var section = new SettingSection(SystemUtil.GetStringResource("SettingSection_Display"));

            section.Add(new ToggleSetting
            {
                SettingData = new AppSettingData <bool>()
                {
                    Title         = SystemUtil.GetStringResource("DisplayTakeImageButtonSetting"),
                    Guide         = SystemUtil.GetStringResource("Guide_DisplayTakeImageButtonSetting"),
                    StateProvider = () => ApplicationSettings.GetInstance().IsShootButtonDisplayed,
                    StateObserver = enabled => ApplicationSettings.GetInstance().IsShootButtonDisplayed = enabled
                }
            });

            section.Add(new ToggleSetting
            {
                SettingData = new AppSettingData <bool>()
                {
                    Title         = SystemUtil.GetStringResource("DisplayHistogram"),
                    Guide         = SystemUtil.GetStringResource("Guide_Histogram"),
                    StateProvider = () => ApplicationSettings.GetInstance().IsHistogramDisplayed,
                    StateObserver = enabled => ApplicationSettings.GetInstance().IsHistogramDisplayed = enabled
                }
            });

            var FocusFrameSetting = new AppSettingData <bool>()
            {
                Title         = SystemUtil.GetStringResource("FocusFrameDisplay"),
                Guide         = SystemUtil.GetStringResource("Guide_FocusFrameDisplay"),
                StateProvider = () => ApplicationSettings.GetInstance().RequestFocusFrameInfo,
                StateObserver = enabled =>
                {
                    ApplicationSettings.GetInstance().RequestFocusFrameInfo = enabled;
                    // todo: support to show focus frames
                    //await SetupFocusFrame(enabled);
                    //if (!enabled) { _FocusFrameSurface.ClearFrames(); }
                }
            };

            section.Add(new ToggleSetting {
                SettingData = FocusFrameSetting
            });

            section.Add(new ToggleSetting
            {
                SettingData = new AppSettingData <bool>()
                {
                    Title         = SystemUtil.GetStringResource("LiveviewRotation"),
                    Guide         = SystemUtil.GetStringResource("LiveviewRotation_guide"),
                    StateProvider = () => ApplicationSettings.GetInstance().LiveviewRotationEnabled,
                    StateObserver = enabled =>
                    {
                        ApplicationSettings.GetInstance().LiveviewRotationEnabled = enabled;
                        // todo: support to rotate liveview image
                        //if (enabled && target != null && target.Status != null)
                        //{
                        //    RotateLiveviewImage(target.Status.LiveviewOrientationAsDouble);
                        //}
                        //else
                        //{
                        //    RotateLiveviewImage(0);
                        //}
                    }
                }
            });

            section.Add(new ToggleSetting
            {
                SettingData = new AppSettingData <bool>()
                {
                    Title         = SystemUtil.GetStringResource("FramingGrids"),
                    Guide         = SystemUtil.GetStringResource("Guide_FramingGrids"),
                    StateProvider = () => ApplicationSettings.GetInstance().FramingGridEnabled,
                    StateObserver = enabled =>
                    {
                        ApplicationSettings.GetInstance().FramingGridEnabled = enabled;
                        // screen_view_data.FramingGridDisplayed = enabled;
                    }
                }
            });

            var gridTypePanel = new ComboBoxSetting(new AppSettingData <int>()
            {
                Title         = SystemUtil.GetStringResource("AssistPattern"),
                StateProvider = () => (int)ApplicationSettings.GetInstance().GridType - 1,
                StateObserver = setting =>
                {
                    if (setting < 0)
                    {
                        return;
                    }
                    ApplicationSettings.GetInstance().GridType = (FramingGridTypes)(setting + 1);
                },
                Candidates = SettingValueConverter.FromFramingGrid(EnumUtil <FramingGridTypes> .GetValueEnumerable())
            });

            gridTypePanel.SetBinding(VisibilityProperty, new Binding
            {
                Source    = ApplicationSettings.GetInstance(),
                Path      = new PropertyPath(nameof(ApplicationSettings.FramingGridEnabled)),
                Mode      = BindingMode.OneWay,
                Converter = new BoolToVisibilityConverter(),
            });
            section.Add(gridTypePanel);

            var gridColorPanel = new ComboBoxSetting(new AppSettingData <int>()
            {
                Title         = SystemUtil.GetStringResource("FramingGridColor"),
                StateProvider = () => (int)ApplicationSettings.GetInstance().GridColor,
                StateObserver = setting =>
                {
                    if (setting < 0)
                    {
                        return;
                    }
                    ApplicationSettings.GetInstance().GridColor = (FramingGridColors)setting;
                },
                Candidates = SettingValueConverter.FromFramingGridColor(EnumUtil <FramingGridColors> .GetValueEnumerable())
            });

            gridColorPanel.SetBinding(VisibilityProperty, new Binding
            {
                Source    = ApplicationSettings.GetInstance(),
                Path      = new PropertyPath(nameof(ApplicationSettings.FramingGridEnabled)),
                Mode      = BindingMode.OneWay,
                Converter = new BoolToVisibilityConverter(),
            });
            section.Add(gridColorPanel);

            var fibonacciOriginPanel = new ComboBoxSetting(new AppSettingData <int>()
            {
                Title         = SystemUtil.GetStringResource("FibonacciSpiralOrigin"),
                StateProvider = () => (int)ApplicationSettings.GetInstance().FibonacciLineOrigin,
                StateObserver = setting =>
                {
                    if (setting < 0)
                    {
                        return;
                    }
                    ApplicationSettings.GetInstance().FibonacciLineOrigin = (FibonacciLineOrigins)setting;
                },
                Candidates = SettingValueConverter.FromFibonacciLineOrigin(EnumUtil <FibonacciLineOrigins> .GetValueEnumerable())
            });

            fibonacciOriginPanel.SetBinding(VisibilityProperty, new Binding
            {
                Source    = ApplicationSettings.GetInstance(),
                Path      = new PropertyPath(nameof(ApplicationSettings.IsFibonacciSpiralEnabled)),
                Mode      = BindingMode.OneWay,
                Converter = new BoolToVisibilityConverter(),
            });
            section.Add(fibonacciOriginPanel);

            section.Add(new ToggleSetting
            {
                SettingData = new AppSettingData <bool>()
                {
                    Title         = SystemUtil.GetStringResource("ForcePhoneView"),
                    Guide         = SystemUtil.GetStringResource("ForcePhoneView_Guide"),
                    StateProvider = () => ApplicationSettings.GetInstance().ForcePhoneView,
                    StateObserver = enabled => ApplicationSettings.GetInstance().ForcePhoneView = enabled
                }
            });

            section.Add(new ToggleSetting
            {
                SettingData = new AppSettingData <bool>()
                {
                    Title         = SystemUtil.GetStringResource("ShowKeyCheatSheet"),
                    Guide         = SystemUtil.GetStringResource("ShowKeyCheatSheet_Guide"),
                    StateProvider = () => ApplicationSettings.GetInstance().ShowKeyCheatSheet,
                    StateObserver = enabled => ApplicationSettings.GetInstance().ShowKeyCheatSheet = enabled
                }
            });

            return(section);
        }
Пример #19
0
 public ServerAppSettingSet()
 {
     VirtualRoot.BuildCmdPath <SetServerAppSettingCommand>(action: message => {
         if (message.AppSetting == null)
         {
             return;
         }
         AppSettingData oldValue;
         if (_dicByKey.TryGetValue(message.AppSetting.Key, out AppSettingData entity))
         {
             oldValue = new AppSettingData {
                 Key   = entity.Key,
                 Value = entity.Value
             };
             entity.Value = message.AppSetting.Value;
         }
         else
         {
             entity   = AppSettingData.Create(message.AppSetting);
             oldValue = null;
             _dicByKey.Add(message.AppSetting.Key, entity);
         }
         Server.AppSettingService.SetAppSettingAsync(entity, (response, exception) => {
             if (!response.IsSuccess())
             {
                 if (oldValue == null)
                 {
                     _dicByKey.Remove(message.AppSetting.Key);
                 }
                 else
                 {
                     entity.Value = oldValue.Value;
                 }
                 Write.UserFail(response.ReadMessage(exception));
                 VirtualRoot.RaiseEvent(new ServerAppSettingSetedEvent(message.Id, entity));
             }
         });
         VirtualRoot.RaiseEvent(new ServerAppSettingSetedEvent(message.Id, entity));
     });
     VirtualRoot.BuildCmdPath <SetServerAppSettingsCommand>(action: message => {
         if (message.AppSettings == null)
         {
             return;
         }
         foreach (var item in message.AppSettings)
         {
             AppSettingData oldValue;
             if (_dicByKey.TryGetValue(item.Key, out AppSettingData entity))
             {
                 oldValue = new AppSettingData {
                     Key   = entity.Key,
                     Value = entity.Value
                 };
                 entity.Value = item.Value;
             }
             else
             {
                 entity   = AppSettingData.Create(item);
                 oldValue = null;
                 _dicByKey.Add(item.Key, entity);
             }
             VirtualRoot.RaiseEvent(new ServerAppSettingSetedEvent(message.Id, entity));
         }
         Server.AppSettingService.SetAppSettingsAsync(message.AppSettings.Select(a => AppSettingData.Create(a)).ToList(), (response, exception) => {
         });
     });
 }
Пример #20
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);
        }
Пример #21
0
 public ServerAppSettingSet(INTMinerRoot root)
 {
     _root = root;
     VirtualRoot.Window <ChangeServerAppSettingCommand>("处理设置AppSetting命令", LogEnum.DevConsole,
                                                        action: message => {
         if (message.AppSetting == null)
         {
             return;
         }
         AppSettingData oldValue;
         if (_dicByKey.TryGetValue(message.AppSetting.Key, out AppSettingData entity))
         {
             oldValue = new AppSettingData {
                 Key   = entity.Key,
                 Value = entity.Value
             };
             entity.Value = message.AppSetting.Value;
         }
         else
         {
             entity   = AppSettingData.Create(message.AppSetting);
             oldValue = null;
             _dicByKey.Add(message.AppSetting.Key, entity);
         }
         Server.AppSettingService.SetAppSettingAsync(entity, (response, exception) => {
             if (!response.IsSuccess())
             {
                 if (oldValue == null)
                 {
                     _dicByKey.Remove(message.AppSetting.Key);
                 }
                 else
                 {
                     entity.Value = oldValue.Value;
                 }
                 Write.UserFail(response.ReadMessage(exception));
                 VirtualRoot.Happened(new ServerAppSettingChangedEvent(entity));
             }
         });
         VirtualRoot.Happened(new ServerAppSettingChangedEvent(entity));
     });
     VirtualRoot.Window <ChangeServerAppSettingsCommand>("处理批量设置AppSetting命令", LogEnum.DevConsole,
                                                         action: message => {
         if (message.AppSettings == null)
         {
             return;
         }
         foreach (var item in message.AppSettings)
         {
             AppSettingData oldValue;
             if (_dicByKey.TryGetValue(item.Key, out AppSettingData entity))
             {
                 oldValue = new AppSettingData {
                     Key   = entity.Key,
                     Value = entity.Value
                 };
                 entity.Value = item.Value;
             }
             else
             {
                 entity   = AppSettingData.Create(item);
                 oldValue = null;
                 _dicByKey.Add(item.Key, entity);
             }
             VirtualRoot.Happened(new ServerAppSettingChangedEvent(entity));
         }
         Server.AppSettingService.SetAppSettingsAsync(message.AppSettings.Select(a => AppSettingData.Create(a)).ToList(), (response, exception) => {
         });
     });
 }
Пример #22
0
        public void DebugLogToggle_Loaded(object sender, RoutedEventArgs e)
        {
            var data = new AppSettingData <bool>()
            {
                Title = SystemUtil.GetStringResource("DebugLog_Setting_Title"),
                Guide = SystemUtil.GetStringResource("DebugLog_Setting_Guide")
            };

            data.StateProvider = () => ApplicationSettings.GetInstance().EnableDebugLogging;
            data.StateObserver = async(enabled) =>
            {
                ApplicationSettings.GetInstance().EnableDebugLogging = enabled;
                if (enabled)
                {
                    if (logFiles.Count != 0)
                    {
                        dialogInfo.DescriptionId   = "DebugLog_DetectPreviousDialog_Description";
                        dialogInfo.PrimaryTextId   = "DebugLog_DetectPreviousDialog_Deny";
                        dialogInfo.SecondaryTextId = "DebugLog_DetectPreviousDialog_Accept";
                        switch (await DebugLogDialog.ShowAsync())
                        {
                        case ContentDialogResult.Primary:
                            foreach (var file in logFiles)
                            {
                                await file.DeleteAsync();
                            }
                            LoadLogFiles();
                            break;

                        case ContentDialogResult.Secondary:     // Previous operation may be finished abnormally.
                            await DebugUtil.ZipLogFileDir();

                            foreach (var file in logFiles)
                            {
                                await file.DeleteAsync();
                            }
                            LoadLogFiles();
                            await SendLogFile(await DebugUtil.LatestLogFile());

                            break;

                        default:
                            break;
                        }
                        ApplicationSettings.GetInstance().EnableDebugLogging = false;
                        data.CurrentSetting = false;
                        return;
                    }

                    dialogInfo.DescriptionId   = "DebugLog_EnableDialog_Description";
                    dialogInfo.PrimaryTextId   = "DebugLog_EnableDialog_Deny";
                    dialogInfo.SecondaryTextId = "DebugLog_EnableDialog_Accept";
                    switch (await DebugLogDialog.ShowAsync())
                    {
                    case ContentDialogResult.Secondary:
                        break;

                    case ContentDialogResult.Primary:
                    default:
                        ApplicationSettings.GetInstance().EnableDebugLogging = false;
                        data.CurrentSetting = false;
                        return;
                    }

                    await DebugUtil.GrubFile();

                    LoadLogFiles();
                }
                else
                {
                    if (!DebugUtil.ReleaseFile())
                    {
                        return;
                    }
                    var task = Task.Run(async() =>
                    {
                        await DebugUtil.ZipLogFileDir();
                        foreach (var file in logFiles)
                        {
                            await file.DeleteAsync();
                        }
                        LoadLogFiles();

                        await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                        {
                            dialogInfo.DescriptionId   = "DebugLog_LaunchEmailDialog_Description";
                            dialogInfo.PrimaryTextId   = "DebugLog_LaunchEmailDialog_Deny";
                            dialogInfo.SecondaryTextId = "DebugLog_LaunchEmailDialog_Accept";
                            switch (await DebugLogDialog.ShowAsync())
                            {
                            case ContentDialogResult.Secondary:
                                await SendLogFile(await DebugUtil.LatestLogFile());
                                break;

                            case ContentDialogResult.Primary:
                            default:
                                ApplicationSettings.GetInstance().EnableDebugLogging = false;
                                data.CurrentSetting = false;
                                return;
                            }
                        });
                    });
                }
            };
            (sender as ToggleSetting).SettingData = data;
        }
Пример #23
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);
        }