fasdfsa commited on
Commit
2931426
·
1 Parent(s): 3510ac4

Alt + S 截图加入O键切换 OCR 语言类型

Browse files
src/ScreenGrab.Sample/MainWindow.xaml.cs CHANGED
@@ -34,11 +34,11 @@ public partial class MainWindow
34
  if (ScreenGrabber.IsCapturing) return;
35
  // https://github.com/wuqinchao/ScreenCapturer
36
  // 替代品
37
- ScreenGrabber.OnCaptured = async bitmap => await ScreenshotCallbackAsync(bitmap, null);
38
  ScreenGrabber.Capture(true);
39
  }
40
 
41
- internal async Task ScreenshotCallbackAsync(Bitmap? bitmap, CancellationToken? token = null)
42
  {
43
  if (bitmap == null)
44
  {
 
34
  if (ScreenGrabber.IsCapturing) return;
35
  // https://github.com/wuqinchao/ScreenCapturer
36
  // 替代品
37
+ ScreenGrabber.OnCaptured = async (bitmap, type) => await ScreenshotCallbackAsync(bitmap, type, null);
38
  ScreenGrabber.Capture(true);
39
  }
40
 
41
+ internal async Task ScreenshotCallbackAsync(Bitmap? bitmap, string type, CancellationToken? token = null)
42
  {
43
  if (bitmap == null)
44
  {
src/ScreenGrab/ScreenGrab.csproj CHANGED
@@ -6,6 +6,7 @@
6
  <UseWPF>true</UseWPF>
7
  <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8
  <ImplicitUsings>enable</ImplicitUsings>
 
9
  </PropertyGroup>
10
 
11
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
 
6
  <UseWPF>true</UseWPF>
7
  <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8
  <ImplicitUsings>enable</ImplicitUsings>
9
+ <OutputType>Library</OutputType>
10
  </PropertyGroup>
11
 
12
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
src/ScreenGrab/ScreenGrabView.xaml CHANGED
@@ -75,7 +75,7 @@
75
  ChildMargin="3"
76
  ChildVerticalAlignment="Center"
77
  Columns="*, *"
78
- RowCount="2"
79
  RowHeight="30">
80
  <Grid.Resources>
81
  <Style TargetType="StackPanel">
@@ -98,6 +98,10 @@
98
  <local:UcCharacter DisplayChar="F" />
99
  </StackPanel>
100
  <TextBlock x:Name="FreezeTb" Text="取消冻结窗口" />
 
 
 
 
101
  </local:AutoGrid>
102
  </Border>
103
  </Grid>
 
75
  ChildMargin="3"
76
  ChildVerticalAlignment="Center"
77
  Columns="*, *"
78
+ RowCount="3"
79
  RowHeight="30">
80
  <Grid.Resources>
81
  <Style TargetType="StackPanel">
 
98
  <local:UcCharacter DisplayChar="F" />
99
  </StackPanel>
100
  <TextBlock x:Name="FreezeTb" Text="取消冻结窗口" />
101
+ <StackPanel>
102
+ <local:UcCharacter DisplayChar="O" />
103
+ </StackPanel>
104
+ <TextBlock x:Name="OCRTYPE" Text="微信识别" />
105
  </local:AutoGrid>
106
  </Border>
107
  </Grid>
src/ScreenGrab/ScreenGrabView.xaml.cs CHANGED
@@ -12,6 +12,12 @@ using Size = System.Windows.Size;
12
 
13
  namespace ScreenGrab;
14
 
 
 
 
 
 
 
15
  /// <summary>
16
  /// Extracted from the project <see href="https://github.com/TheJoeFin/Text-Grab" />
17
  /// </summary>
@@ -19,7 +25,7 @@ public partial class ScreenGrabView
19
  {
20
  #region Constructors
21
 
22
- public ScreenGrabView(Action<Bitmap>? action, bool isAuxiliary = false)
23
  {
24
  InitializeComponent();
25
  _onImageCaptured = action;
@@ -33,6 +39,10 @@ public partial class ScreenGrabView
33
  public Action? OnGrabClose { get; set; }
34
  private DisplayInfo? CurrentScreen { get; set; }
35
 
 
 
 
 
36
  #endregion Properties
37
 
38
  #region Fields
@@ -54,7 +64,7 @@ public partial class ScreenGrabView
54
  private const double SelectBorderThickness = 2;
55
  private readonly Color _borderColor = Color.FromArgb(255, 146, 202, 244);
56
 
57
- private readonly Action<Bitmap>? _onImageCaptured;
58
  private readonly bool _isAuxiliary;
59
 
60
  #endregion Fields
@@ -123,6 +133,18 @@ public partial class ScreenGrabView
123
  case Key.F:
124
  FreezeUnfreezeAllScreenGrabs();
125
  break;
 
 
 
 
 
 
 
 
 
 
 
 
126
  }
127
  }
128
 
@@ -371,7 +393,7 @@ public partial class ScreenGrabView
371
  var bitmap = correctedRegion.GetRegionOfScreenAsBitmap();
372
  CloseAllScreenGrabs();
373
 
374
- _onImageCaptured?.Invoke(bitmap);
375
  }
376
 
377
  private void PanSelection(Point movingPoint)
 
12
 
13
  namespace ScreenGrab;
14
 
15
+ public enum OcrType
16
+ {
17
+ WechatOCR,
18
+ ComicOCR
19
+ }
20
+
21
  /// <summary>
22
  /// Extracted from the project <see href="https://github.com/TheJoeFin/Text-Grab" />
23
  /// </summary>
 
25
  {
26
  #region Constructors
27
 
28
+ public ScreenGrabView(Action<Bitmap, string>? action, bool isAuxiliary = false)
29
  {
30
  InitializeComponent();
31
  _onImageCaptured = action;
 
39
  public Action? OnGrabClose { get; set; }
40
  private DisplayInfo? CurrentScreen { get; set; }
41
 
42
+ public OcrType _OcrMode { get; set; } = OcrType.WechatOCR;
43
+
44
+
45
+
46
  #endregion Properties
47
 
48
  #region Fields
 
64
  private const double SelectBorderThickness = 2;
65
  private readonly Color _borderColor = Color.FromArgb(255, 146, 202, 244);
66
 
67
+ private readonly Action<Bitmap, string>? _onImageCaptured;
68
  private readonly bool _isAuxiliary;
69
 
70
  #endregion Fields
 
133
  case Key.F:
134
  FreezeUnfreezeAllScreenGrabs();
135
  break;
136
+ case Key.O:
137
+ if (_OcrMode == OcrType.WechatOCR)
138
+ {
139
+ _OcrMode = OcrType.ComicOCR;
140
+ OCRTYPE.Text = "漫画识别";
141
+ }
142
+ else if (_OcrMode == OcrType.ComicOCR)
143
+ {
144
+ _OcrMode = OcrType.WechatOCR;
145
+ OCRTYPE.Text = "微信识别";
146
+ }
147
+ break;
148
  }
149
  }
150
 
 
393
  var bitmap = correctedRegion.GetRegionOfScreenAsBitmap();
394
  CloseAllScreenGrabs();
395
 
396
+ _onImageCaptured?.Invoke(bitmap, OCRTYPE.Text);
397
  }
398
 
399
  private void PanSelection(Point movingPoint)
src/ScreenGrab/ScreenGrabber.cs CHANGED
@@ -5,11 +5,19 @@ using ScreenGrab.Extensions;
5
 
6
  namespace ScreenGrab;
7
 
 
 
 
 
 
 
8
  public abstract class ScreenGrabber
9
  {
10
  public static bool IsCapturing { get; private set; }
11
 
12
- public static Action<Bitmap>? OnCaptured { get; set; }
 
 
13
 
14
  public static void Capture(bool isAuxiliary = false)
15
  {
 
5
 
6
  namespace ScreenGrab;
7
 
8
+ //public enum OcrType
9
+ //{
10
+ // WechatOCR,
11
+ // ComicOCR
12
+ //}
13
+
14
  public abstract class ScreenGrabber
15
  {
16
  public static bool IsCapturing { get; private set; }
17
 
18
+ //public static OcrType _OcrMode { get; set; } = OcrType.WechatOCR;
19
+
20
+ public static Action<Bitmap, string>? OnCaptured { get; set; }
21
 
22
  public static void Capture(bool isAuxiliary = false)
23
  {
src/WpfEditor/TreeMenuPage.xaml.cs CHANGED
@@ -28,14 +28,14 @@ namespace WpfEditor
28
  if (ScreenGrabber.IsCapturing) return;
29
  // https://github.com/wuqinchao/ScreenCapturer
30
  // 替代品
31
- ScreenGrabber.OnCaptured = async bitmap => await ScreenshotCallbackAsync(bitmap, null);
32
  ScreenGrabber.Capture(true);
33
 
34
  });
35
 
36
  }
37
 
38
- private async Task ScreenshotCallbackAsync(Bitmap? bitmap, CancellationToken? token = null)
39
  {
40
  if (bitmap == null)
41
  {
@@ -79,7 +79,13 @@ namespace WpfEditor
79
  //win.Show();
80
 
81
  var ReviseEditWindow = new MainWindow(EditorMode.ReviseEdit);
82
- ReviseEditWindow._ocrMode = OcrMode.ComicOcr;
 
 
 
 
 
 
83
  ReviseEditWindow.WindowState = WindowState.Maximized;
84
  ReviseEditWindow.Show();
85
  ReviseEditWindow.handle_comicocr_open_img(tempFile);
 
28
  if (ScreenGrabber.IsCapturing) return;
29
  // https://github.com/wuqinchao/ScreenCapturer
30
  // 替代品
31
+ ScreenGrabber.OnCaptured = async (bitmap, type) => await ScreenshotCallbackAsync(bitmap, type, null);
32
  ScreenGrabber.Capture(true);
33
 
34
  });
35
 
36
  }
37
 
38
+ private async Task ScreenshotCallbackAsync(Bitmap? bitmap, string type, CancellationToken? token = null)
39
  {
40
  if (bitmap == null)
41
  {
 
79
  //win.Show();
80
 
81
  var ReviseEditWindow = new MainWindow(EditorMode.ReviseEdit);
82
+ if (type == "微信识别")
83
+ {
84
+ ReviseEditWindow._ocrMode = OcrMode.WeChatOcr;
85
+ } else if (type == "漫画识别")
86
+ {
87
+ ReviseEditWindow._ocrMode = OcrMode.ComicOcr;
88
+ }
89
  ReviseEditWindow.WindowState = WindowState.Maximized;
90
  ReviseEditWindow.Show();
91
  ReviseEditWindow.handle_comicocr_open_img(tempFile);