コード例 #1
0
ファイル: Screenulate.cs プロジェクト: Netdex/Screenulate
        private void ProcessFrame(bool instant)
        {
            if (!btnScreenshot.Enabled)
            {
                return;
            }
            if (!File.Exists(openFileDialogTesseract.FileName))
            {
                MessageBox.Show(this, "Tesseract-OCR path not configured!", "Screenulate",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            tesseractProgress.Style = ProgressBarStyle.Marquee;
            btnScreenshot.Enabled   = false;

            var screenshotForm = new ScreenshotForm {
                Rectangle = _lastScreenshotRect
            };

            if (instant)
            {
                screenshotForm.CaptureImage(_lastScreenshotRect);
            }
            else
            {
                screenshotForm.ShowDialog(this);
            }

            if (screenshotForm.Bitmap == null)
            {
                tesseractProgress.Style = ProgressBarStyle.Blocks;
                btnScreenshot.Enabled   = true;
                return;
            }

            _lastScreenshotRect = screenshotForm.Rectangle;

            IImage oldImage = previewBox.Image;

            previewBox.Image = new Image <Bgr, byte>(screenshotForm.Bitmap);
            oldImage?.Dispose();
            var processor = new TesseractProcessor(openFileDialogTesseract.FileName, previewBox.DisplayedImage);

            processor.Process();

            processor.Completed += TesseractProcessor_Completed;
            processor.Finished  += TesseractProcessor_Finished;
            processor.Error     += (sender, args) =>
            {
                MessageBox.Show($@"{args.GetException().Message}", "Screenulate", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            };
        }