private void ChooseAreaBtn_Click(object sender, RoutedEventArgs e) { if (isAllWin == false && SelectedHwnd == 0) { HandyControl.Controls.Growl.Error(Application.Current.Resources["ChooseOCRAreaPage_NextErrorHint"].ToString()); return; } BitmapImage img; if (isAllWin == true) { img = ImageProcFunc.ImageToBitmapImage(ScreenCapture.GetAllWindow()); } else { img = ImageProcFunc.ImageToBitmapImage(ScreenCapture.GetWindowCapture((IntPtr)SelectedHwnd)); } ScreenCaptureWindow scw = new ScreenCaptureWindow(img); scw.Width = img.PixelWidth; scw.Height = img.PixelHeight; scw.Topmost = true; scw.Top = 0; scw.Left = 0; scw.Show(); }
private void ChooseAreaBtn_Click(object sender, RoutedEventArgs e) { if (!isAllWin && SelectedHwnd == 0) { HandyControl.Controls.Growl.Error(Application.Current.Resources["ChooseOCRAreaPage_NextErrorHint"].ToString()); return; } BitmapImage img; if (isAllWin) { img = ImageProcFunc.ImageToBitmapImage(ScreenCapture.GetAllWindow()); } else { img = ImageProcFunc.ImageToBitmapImage(ScreenCapture.GetWindowCapture((IntPtr)SelectedHwnd)); } ScreenCaptureWindow scw = new ScreenCaptureWindow(img); scw.Width = img.Width; scw.Height = img.Height; scw.Topmost = true; scw.Top = 0; scw.Left = 0; scw.ShowDialog(); // 不用Show()因为需要阻塞等待结果 RenewAreaBtn_Click(null, null); // 显示结果 ConfirmBtn.IsEnabled = true; }
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"; } } }
private void ChooseAreaBtn_Click(object sender, RoutedEventArgs e) { if (isAllWin == false && SelectedHwnd == 0) { HandyControl.Controls.Growl.Error("请先选择窗口!"); return; } BitmapImage img; if (isAllWin == true) { img = ImageProcFunc.ImageToBitmapImage(ScreenCapture.GetAllWindow()); } else { img = ImageProcFunc.ImageToBitmapImage(ScreenCapture.GetWindowCapture((IntPtr)SelectedHwnd)); } ScreenCaptureWindow scw = new ScreenCaptureWindow(img); scw.Width = img.PixelWidth; scw.Height = img.PixelHeight; scw.WindowStartupLocation = WindowStartupLocation.CenterScreen; scw.Show(); }
private void RenewAreaBtn_Click(object sender, RoutedEventArgs e) { OCRArea = ScreenCaptureWindow.OCRArea; Common.ocr.SetOCRArea((IntPtr)SelectedHwnd, OCRArea, isAllWin); OCRAreaPicBox.Source = ImageProcFunc.ImageToBitmapImage( Common.ocr.GetOCRAreaCap()); GC.Collect(); }
private void ThresholdBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { System.Drawing.Bitmap bm = (System.Drawing.Bitmap)bmp.Clone(); System.IO.MemoryStream stream = new System.IO.MemoryStream(); ImageProcFunc.Thresholding(bm, (byte)(int)ThresholdBar.Value).Save(stream, System.Drawing.Imaging.ImageFormat.Png); bm.Dispose(); ImageSourceConverter imageSourceConverter = new ImageSourceConverter(); img.Source = (ImageSource)imageSourceConverter.ConvertFrom(stream); }
private void RenewAreaBtn_Click(object sender, RoutedEventArgs e) { System.Drawing.Image img = Common.ocr.GetOCRAreaCap(); SrcImg.Source = ImageProcFunc.ImageToBitmapImage(img); DstImg.Source = ImageProcFunc.ImageToBitmapImage(ImageProcFunc.Auto_Thresholding(new System.Drawing.Bitmap(img), ImageProcFunc.lstHandleFun[ImageProcFunclist[HandleFuncCombox.SelectedIndex]])); GC.Collect(); }
/// <summary> /// 全局OCR /// </summary> public static void GlobalOCR() { BitmapImage img = ImageProcFunc.ImageToBitmapImage(ScreenCapture.GetAllWindow()); ScreenCaptureWindow scw = new ScreenCaptureWindow(img, 2); scw.Width = img.Width; scw.Height = img.Height; scw.Left = 0; scw.Top = 0; scw.Show(); }
private void HandleFuncCombox_SelectionChanged(object sender, SelectionChangedEventArgs e) { System.Drawing.Image img = Common.ocr.GetOCRAreaCap(); SrcImg.Source = ImageProcFunc.ImageToBitmapImage(img); try { DstImg.Source = ImageProcFunc.ImageToBitmapImage(ImageProcFunc.Auto_Thresholding(new System.Drawing.Bitmap(img), ImageProcFunc.lstHandleFun[ImageProcFunclist[HandleFuncCombox.SelectedIndex]])); } catch (NullReferenceException ex) { Growl.Error(Application.Current.Resources["ChooseOCRAreaPage_RenewErrorHint"].ToString()); return; } GC.Collect(); }
/// <summary> /// 游戏库瀑布流初始化 /// </summary> private void GameLibraryPanel_Init() { List <System.Windows.Media.SolidColorBrush> bushLst = new List <System.Windows.Media.SolidColorBrush> { System.Windows.Media.Brushes.CornflowerBlue, System.Windows.Media.Brushes.IndianRed, System.Windows.Media.Brushes.Orange, System.Windows.Media.Brushes.ForestGreen }; if (gameInfolst != null) { for (int i = 0; i < gameInfolst.Count; i++) { Border back = new Border(); GameLibraryPanel.RegisterName("game" + i, back); back.Name = "game" + i; Grid gd = new Grid(); back.Width = 150; back.Margin = new Thickness(5); back.Child = gd; back.Background = bushLst[i % 4]; TextBlock tb = new TextBlock(); tb.Text = gameInfolst[i].GameName; tb.Foreground = System.Windows.Media.Brushes.White; tb.HorizontalAlignment = HorizontalAlignment.Left; tb.VerticalAlignment = VerticalAlignment.Bottom; tb.Margin = new Thickness(3); gd.Children.Add(tb); System.Windows.Controls.Image ico = new System.Windows.Controls.Image(); ico.Source = ImageProcFunc.ImageToBitmapImage(ImageProcFunc.GetAppIcon(gameInfolst[i].FilePath)); ico.HorizontalAlignment = HorizontalAlignment.Center; ico.VerticalAlignment = VerticalAlignment.Center; ico.Height = 50; ico.Width = 50; gd.Children.Add(ico); back.MouseEnter += Border_MouseEnter; back.MouseLeave += Border_MouseLeave; back.MouseLeftButtonDown += Border_MouseLeftButtonDown; GameLibraryPanel.Children.Add(back); } } }
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; } }
private void HandleFuncCombox_SelectionChanged(object sender, SelectionChangedEventArgs e) { System.Drawing.Image img = Common.ocr.GetOCRAreaCap(); SrcImg.Source = ImageProcFunc.ImageToBitmapImage(img); string imgFunc = ""; if (ImageProcFunclist != null) { imgFunc = ImageProcFunc.lstHandleFun[ImageProcFunclist[HandleFuncCombox.SelectedIndex]]; } DstImg.Source = ImageProcFunc.ImageToBitmapImage( ImageProcFunc.Auto_Thresholding(new System.Drawing.Bitmap(img), imgFunc, paramValue, 0) ); Common.appSettings.OCR_PreprocessMethod = imgFunc; Common.ocr.SetImgFunc(imgFunc, paramValue, 0); GC.Collect(); }
private void ChooseAreaBtn_Click(object sender, RoutedEventArgs e) { if (!isAllWin && SelectedHwnd == 0) { HandyControl.Controls.Growl.Error(Application.Current.Resources["ChooseOCRAreaPage_NextErrorHint"].ToString()); return; } BitmapImage img; if (isAllWin) { img = ImageProcFunc.ImageToBitmapImage(ScreenCapture.GetAllWindow()); } else { img = ImageProcFunc.ImageToBitmapImage(ScreenCapture.GetWindowCapture((IntPtr)SelectedHwnd)); } ScreenCaptureWindow scw = new ScreenCaptureWindow(img); scw.WindowState = WindowState.Maximized; scw.Show(); }
/// <summary> /// 游戏库瀑布流初始化 /// </summary> private void GameLibraryPanel_Init() { Random random = new Random(); var bushLst = new List <SolidColorBrush> { System.Windows.Media.Brushes.CornflowerBlue, System.Windows.Media.Brushes.IndianRed, System.Windows.Media.Brushes.Orange, System.Windows.Media.Brushes.ForestGreen }; if (gameInfoList != null) { for (var i = 0; i < gameInfoList.Count; i++) { var tb = new TextBlock() { Text = gameInfoList[i].GameName, Foreground = System.Windows.Media.Brushes.White, VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(3) }; var ico = new System.Windows.Controls.Image() { Source = ImageProcFunc.ImageToBitmapImage(ImageProcFunc.GetAppIcon(gameInfoList[i].FilePath)), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Height = 64, Width = 64 }; var gd = new Grid(); gd.Children.Add(ico); gd.Children.Add(tb); var back = new Border() { Name = "game" + i, Width = 150, Child = gd, Margin = new Thickness(5), Background = bushLst[i % 4], }; back.MouseEnter += Border_MouseEnter; back.MouseLeave += Border_MouseLeave; back.MouseLeftButtonDown += Back_MouseLeftButtonDown; GameLibraryPanel.RegisterName("game" + i, back); GameLibraryPanel.Children.Add(back); } } var textBlock = new TextBlock() { Text = Application.Current.Resources["MainWindow_ScrollViewer_AddNewGame"].ToString(), Foreground = System.Windows.Media.Brushes.White, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(3) }; var grid = new Grid(); grid.Children.Add(textBlock); var border = new Border() { Name = "AddNewName", Width = 150, Child = grid, Margin = new Thickness(5), Background = (SolidColorBrush)this.Resources["Foreground"] }; border.MouseEnter += Border_MouseEnter; border.MouseLeave += Border_MouseLeave; border.MouseLeftButtonDown += Border_MouseLeftButtonDown; GameLibraryPanel.RegisterName("AddNewGame", border); GameLibraryPanel.Children.Add(border); }