private void Window_KeyDown(object sender, KeyEventArgs e) { if (e.Key != Key.Escape) { return; } if (!_dragging) { _ocrSnippetWindow?.Show(); Close(); return; } BrdWrapper.Width = BrdWrapper.Height = 0; _dragging = false; }
private async void Window_MouseUp(object sender, MouseButtonEventArgs e) { if (_dragging) { var end = e.GetPosition(this); var selection = GetSelection(end); if (!selection.IsEmpty) { // Hide overlay before capturing screenshot Hide(); await Task.Delay(TimeSpan.FromMilliseconds(100)); // Capture screenshot of selected region var original = new Bitmap(ScreenshotCapture.TakeScreenshot()) .Crop(selection) .CropToContent(); // Invert colors of screenshot if needed to ensure good OCR result var modified = original.Scale(2); if (modified.IsDark(50)) { modified = modified.InvertColors(); } var text = modified.ToBlackAndWhite().Ocr().Item1; var pair = new BitmapTextPair( original.ToImageSource(), modified.ToImageSource(), text ); // Launch snippet manager _ocrSnippetWindow.Model.BitmapPairs.Add(pair); _ocrSnippetWindow.Show(); Close(); return; } } _dragging = false; _startDrag = default; e.Handled = true; }