コード例 #1
0
        private void InkCanvasMeasure_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                iniP = e.GetPosition(inkCanvasMeasure);
            }

            if (e.ChangedButton == MouseButton.Right)
            {
                Bitmap bmpImage = new Bitmap(DicPath + "\\" + ComicImgList[CurrentPos]);
                Bitmap bmp      = bmpImage.Clone(selectRect, bmpImage.PixelFormat);

                ImageProcWindow ipw = new ImageProcWindow(bmp);
                ipw.ShowDialog();

                if (File.Exists(Environment.CurrentDirectory + "\\comicTemp.png"))
                {
                    Bitmap bm = new Bitmap(Environment.CurrentDirectory + "\\comicTemp.png");
                    bm = ImageProcFunc.ColorToGrayscale(bm);
                    sourceTextBox.Text = ocr.OCRProcess(bm).Replace("\f", "");
                }
                else
                {
                    sourceTextBox.Text = "OCR error";
                }
            }
        }
コード例 #2
0
        private async void InkCanvasMeasure_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                iniP = e.GetPosition(inkCanvasMeasure);
            }
            else if (e.ChangedButton == MouseButton.Right)
            {
                // 当从右下往左上选择时,宽高会为负,导致出现OutOfMemoryException。因为Width为负,X+Width实际上是减少X
                if (selectRect.Width < 0)
                {
                    selectRect.Location = new System.Drawing.Point(selectRect.X + selectRect.Width, selectRect.Y);
                    selectRect.Size     = new System.Drawing.Size(-selectRect.Width, selectRect.Height);
                }
                if (selectRect.Height < 0)
                {
                    selectRect.Location = new System.Drawing.Point(selectRect.X, selectRect.Y + selectRect.Height);
                    selectRect.Size     = new System.Drawing.Size(selectRect.Width, -selectRect.Height);
                }

                Bitmap bmpImage = new Bitmap(DicPath + "\\" + ComicImgList[CurrentPos]);
                Bitmap bmp      = bmpImage.Clone(selectRect, bmpImage.PixelFormat);
                bmpImage.Dispose();

                ImageProcWindow ipw = new ImageProcWindow(bmp);
                ipw.ShowDialog();
                bmp.Dispose();

                if (File.Exists(Environment.CurrentDirectory + "\\comicTemp.png"))
                {
                    Bitmap bm = new Bitmap(Environment.CurrentDirectory + "\\comicTemp.png");
                    bm = ImageProcFunc.ColorToGrayscale(bm);
                    sourceTextBox.Text = (await ocr.OCRProcessAsync(bm))?.Replace("\f", "");
                    bm.Dispose();
                }
                else
                {
                    sourceTextBox.Text = "OCR error";
                }
                e.Handled = true;
            }
        }