예제 #1
0
        void ProcessImage()
        {
            richTextBoxLog.Clear();

            if (_loadedBitmap == null)
            {
                richTextBoxLog.AppendText("Image Is Not Loaded\n");
                Application.DoEvents();
                return;
            }

            richTextBoxLog.AppendText("Clonning Original Bitmap\n");
            Application.DoEvents();

            var b = BitmapHelper.CloneBitmap(_loadedBitmap);

            var splitCoefficient = (float)numericUpDownSplitColorCoefficient.Value / 1000f;

            richTextBoxLog.AppendText("Splitting Color\n");
            Application.DoEvents();
            b = BitmapHelper.SplitColors(b, splitCoefficient);
            if (_finishAtSplitColor)
            {
                goto FINISH;
            }

            richTextBoxLog.AppendText("Trimming To Black\n");
            Application.DoEvents();
            b = BitmapHelper.TrimToBlack(b);
            if (_finishAtTrimBlack)
            {
                goto FINISH;
            }

            richTextBoxLog.AppendText("Adding Border\n");
            Application.DoEvents();
            b = BitmapHelper.AddBorder(b, (int)numericUpDownBorderSize.Value);
            if (_finishAtAddBorder)
            {
                goto FINISH;
            }

            richTextBoxLog.AppendText("Getting Hexagon Radius\n");
            Application.DoEvents();
            var radius = HexagonConverter.GetHexagonRadiusFromImage(b, 0f);

            richTextBoxLog.AppendText("Hexagon Radius = " + radius + "\n");
            Application.DoEvents();
            if (_finishAtGetHexagonRadius)
            {
                goto FINISH;
            }

            try
            {
                var content = new HexagonConverter(radius, 0f).ParseCorrectBitmap(b);
                _lastParsedContent = content;
                richTextBoxLog.AppendText("Parsed Successfully:\n" + content + "\n");
                Application.DoEvents();
            }
            catch (Exception e)
            {
                richTextBoxLog.AppendText("Error: " + e.Message + "\n");
                Application.DoEvents();
            }


FINISH:
            richTextBoxLog.AppendText("Finished\n");
            Application.DoEvents();
            SetImage(b);
        }