示例#1
0
        private async void CreateOpacityMap()
        {
            DisableControls(true);
            opacityMapInfoLabel.Visible = true;

            try
            {
                string filePath      = filePathTextBox.Text;
                string resultDirPath = GlobalData.ResultFileDirectory;
                FileDataManager.CreateDirectoryIfNotExists(resultDirPath);

                ArgbProcessor argbProc           = new ArgbProcessor(filePath);
                PacketObjMsg  fileCreationPacket = await argbProc.CreateOpacityMapAndNonTransparentImageTaskStart(resultDirPath);

                bool success = (bool)fileCreationPacket.Obj;

                if (!String.IsNullOrEmpty(fileCreationPacket.Msg))
                {
                    MessageBox.Show(fileCreationPacket.Msg);
                }

                if (success)
                {
                    MessageBox.Show("Pomyślnie utworzono pliki!");
                    Process.Start(resultDirPath);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show($"Błąd tworzenia mapy przezroczystości: {exception.Message}");
            }

            opacityMapInfoLabel.Visible = false;
            DisableControls(false);
        }
        private async void LoadImage()
        {
            if (this.loadingInProgress)
            {
                return;
            }

            this.loadingInProgress = true;
            editPanelMainSplitContainer.Panel2.Enabled = false;

            try
            {
                int deadZoneRangeR = Convert.ToInt32(deadZoneRangeRNumericUpDown.Value);
                int deadZoneRangeG = Convert.ToInt32(deadZoneRangeGNumericUpDown.Value);
                int deadZoneRangeB = Convert.ToInt32(deadZoneRangeBNumericUpDown.Value);

                #region Ścieżka - pobieranie / sprawdzanie
                //POBIERANIE ŚCIEŻKI
                string path = "";

                using (OpenFileDialog ofd = new OpenFileDialog())
                {
                    if (ofd.ShowDialog() == DialogResult.OK)
                    {
                        path = ofd.FileName;
                    }
                }

                if (String.IsNullOrWhiteSpace(path))
                {
                    this.loadingInProgress = false;
                    editPanelMainSplitContainer.Panel2.Enabled = true;
                    UpdateInfo("Nie wybrano pliku!");
                    return;
                }

                if (!File.Exists(path))
                {
                    throw new Exception($"plik [{path}] nie istnieje!");
                }

                string extension        = Path.GetExtension(path);
                bool   extensionIsValid = false;

                foreach (string ext in GlobalData.ImageFormats)
                {
                    if (ext.ToLower() == extension || $".{ext.ToLower()}" == extension)
                    {
                        extensionIsValid = true;
                    }
                }

                if (!extensionIsValid)
                {
                    throw new Exception($"plik [{path}] ma nieprawidłowy format [{extension}]");
                }

                #endregion

                #region Przetwarzanie bitmapy źródłowej
                //PRZETWARZANIE BITMAPY ŹRÓDŁOWEJ
                UpdateInfo("Przetwarzanie mapy rozkładu...");
                Bitmap       originalBitmap       = new Bitmap(path);
                PacketObjMsg grayScaleImagePacket = await ArgbProcessor.CreateGrayScaleImageTaskStart(originalBitmap);

                this.sourceBitmap = (Bitmap)grayScaleImagePacket.Obj;

                if (!String.IsNullOrEmpty(grayScaleImagePacket.Msg))
                {
                    MessageBox.Show(grayScaleImagePacket.Msg);
                }

                if (this.sourceBitmap == null)
                {
                    throw new Exception("bitmapa źródłowa jest NULL!");
                }

                //SetPreview(PreviewType.HairMap, (Bitmap)this.sourceBitmap.Clone()); //PODGLĄD #1

                #endregion

                this.bitmapAreaInfo.Clear();

                #region Inicjalizacja stref
                //INICJALIZACJA MAPY STREF
                UpdateInfo("Inicjalizacja mapy stref...");

                PacketObjMsg bmpAreaLoadingPacket = await this.bitmapAreaInfo.LoadBitmapTaskStart(this.sourceBitmap);

                bool bmpAreaLoadingSuccess = (bool)bmpAreaLoadingPacket.Obj;

                if (!String.IsNullOrEmpty(bmpAreaLoadingPacket.Msg))
                {
                    MessageBox.Show(bmpAreaLoadingPacket.Msg);
                }

                if (!bmpAreaLoadingSuccess)
                {
                    throw new Exception("metoda inicjalizująca dane stref zwróciła wartość FALSE!");
                }

                #endregion

                #region Wyodrębnianie typu stref
                //WYODRĘBNIANIE TYPU STREF
                UpdateInfo("Wyodrębnianie stref martwych i stref wpływu...");

                PacketObjMsg areaMarkingPacket = await this.bitmapAreaInfo.GenerateAreasTaskStart(deadZoneRangeR, deadZoneRangeG, deadZoneRangeB);

                bool areaExtractingSuccess = (bool)areaMarkingPacket.Obj;

                if (!String.IsNullOrEmpty(areaMarkingPacket.Msg))
                {
                    MessageBox.Show(areaMarkingPacket.Msg);
                }

                if (!areaExtractingSuccess)
                {
                    throw new Exception("metoda wyodrębniająca strefy zwróciła wartość FALSE!");
                }

                #endregion

                #region Indeksowanie stref
                //WYODRĘBNIANIE INDEKSÓW STREF
                UpdateInfo("Indeksowanie stref...");

                PacketObjMsg areaIndexingPacket = await this.bitmapAreaInfo.GenerateAreaIndexesTaskStart();

                bool areaIndexingSuccess = (bool)areaIndexingPacket.Obj;

                if (!String.IsNullOrEmpty(areaIndexingPacket.Msg))
                {
                    MessageBox.Show(areaIndexingPacket.Msg);
                }

                if (!areaIndexingSuccess)
                {
                    throw new Exception("metoda indeksująca strefy zwróciła wartość FALSE!");
                }

                #endregion

                #region Zwracanie obrazu rezultatu
                //ZWRACANIE OBRAZU REZULTATU
                UpdateInfo("Generowanie obrazu mapy rozłożenia...");
                PacketObjMsg areaPreviewPacket = await this.bitmapAreaInfo.GenerateAreaPreviewImageTaskStart();

                this.hairMapInfoBitmap = (Bitmap)areaPreviewPacket.Obj;

                if (!String.IsNullOrEmpty(areaPreviewPacket.Msg))
                {
                    MessageBox.Show(areaPreviewPacket.Msg);
                }

                if (this.hairMapInfoBitmap == null)
                {
                    throw new Exception("referencja do obrazu podglądu jest NULL!");
                }

                SetPreview(PreviewType.HairMap, this.hairMapInfoBitmap); //PODGLĄD #2

                #endregion

                #region Tworzenie wstępne ustawień stref
                //TWORZENIE USTAWIEŃ STREF/UPDATE UI
                UpdateInfo("Inicjowanie danych ustawień stref...");
                PacketObjMsg areaSettingsPacket = await this.bitmapAreaInfo.GenerateAreaSettingsTaskStart();

                List <AreaSettings> areaSettingsList = (List <AreaSettings>)areaSettingsPacket.Obj;

                if (!String.IsNullOrEmpty(areaSettingsPacket.Msg))
                {
                    MessageBox.Show(areaSettingsPacket.Msg);
                }

                if (areaSettingsList.Count > 100)
                {
                    MessageBox.Show("Ilość odczytanych stref jest zbyt duża! Należy wybrać obraz o mniej zróżnicowanych obszarach jasności lub zmienić zakres martwej strefy!");
                    areaSettingsList.Clear();
                }

                #endregion

                #region Wypełnianie panelu
                //WYPEŁNIANIE PENELU
                UpdateInfo("Dynamiczne generowanie panelu ustawień stref...");
                await GlobalProcessor.SleepTaskStart(200);

                this.uiController.LoadAreaPanel(areaSettingsList);

                #endregion
            }
            catch (Exception exception)
            {
                MessageBox.Show($"Błąd odczytu obrazu: {exception.Message}");
            }

            UpdateInfo("");
            editPanelMainSplitContainer.Panel2.Enabled = true;
            this.loadingInProgress = false;
        }