forked from tianruoyouxin/tianruoocr_last
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FmMain.cs
6880 lines (6546 loc) · 406 KB
/
FmMain.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web;
using System.Windows.Forms;
using CsharpHttpHelper;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV.Util;
using MSScriptControl;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using ShareX.ScreenCaptureLib;
using ZXing;
using ZXing.Common;
using ZXing.QrCode;
namespace 天若OCR文字识别
{
// Token: 0x02000007 RID: 7
public partial class FmMain : Form
{
// Token: 0x06000060 RID: 96 RVA: 0x000074EC File Offset: 0x000056EC
public FmMain()
{
this.set_merge = false;
this.set_split = false;
this.set_split = false;
StaticValue.截图排斥 = false;
this.pinyin_flag = false;
this.tranclick = false;
this.are = new AutoResetEvent(false);
this.imagelist = new List<Image>();
StaticValue.v_notecount = Convert.ToInt32(inihelp.GetValue("配置", "记录数目"));
this.baidu_flags = "";
this.esc = "";
this.voice_count = 0;
this.fmnote = new Fmnote();
this.fmflags = new Fmflags();
this.pubnote = new string[StaticValue.v_notecount];
for (int i = 0; i < StaticValue.v_notecount; i++)
{
this.pubnote[i] = "";
}
StaticValue.v_note = this.pubnote;
StaticValue.mainhandle = base.Handle;
this.Font = new Font(this.Font.Name, 9f / StaticValue.Dpifactor, this.Font.Style, this.Font.Unit, this.Font.GdiCharSet, this.Font.GdiVerticalFont);
this.googleTranslate_txt = "";
this.num_ok = 0;
this.F_factor = Program.factor;
this.components = null;
this.InitializeComponent();
this.nextClipboardViewer = (IntPtr)HelpWin32.SetClipboardViewer((int)base.Handle);
this.InitMinimize();
this.readIniFile();
base.WindowState = FormWindowState.Minimized;
base.Visible = false;
this.split_txt = "";
this.MinimumSize = new Size((int)this.font_base.Width * 23, (int)this.font_base.Height * 24);
FmMain.speak_copy = false;
this.OCR_foreach("");
}
// Token: 0x06000061 RID: 97 RVA: 0x00002399 File Offset: 0x00000599
private void Load_Click(object sender, EventArgs e)
{
base.WindowState = FormWindowState.Minimized;
base.Visible = false;
}
// Token: 0x06000062 RID: 98 RVA: 0x000076C0 File Offset: 0x000058C0
protected override void WndProc(ref Message m)
{
if (m.Msg == 953)
{
this.speaking = false;
}
if (m.Msg == 274 && (int)m.WParam == 61536)
{
base.WindowState = FormWindowState.Minimized;
base.Visible = false;
return;
}
if (m.Msg == 600 && (int)m.WParam == 725)
{
if (inihelp.GetValue("工具栏", "顶置") == "True")
{
base.TopMost = true;
return;
}
base.TopMost = false;
return;
}
else
{
if (m.Msg == 786 && m.WParam.ToInt32() == 530 && this.RichBoxBody.Text != null)
{
this.p_note(this.RichBoxBody.Text);
StaticValue.v_note = this.pubnote;
if (this.fmnote.Created)
{
this.fmnote.Text_note = "";
}
}
if (m.Msg == 786 && m.WParam.ToInt32() == 520)
{
this.fmnote.Show();
this.fmnote.Focus();
this.fmnote.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.fmnote.Width, Screen.PrimaryScreen.WorkingArea.Height - this.fmnote.Height);
this.fmnote.WindowState = FormWindowState.Normal;
return;
}
if (m.Msg == 786 && m.WParam.ToInt32() == 580)
{
HelpWin32.UnregisterHotKey(base.Handle, 205);
this.change_QQ_screenshot = false;
base.FormBorderStyle = FormBorderStyle.None;
base.Hide();
if (this.transtalate_fla == "开启")
{
this.form_width = base.Width / 2;
}
else
{
this.form_width = base.Width;
}
this.form_height = base.Height;
this.minico.Visible = false;
this.minico.Visible = true;
this.menu.Close();
this.menu_copy.Close();
this.auto_fla = "开启";
this.split_txt = "";
this.RichBoxBody.Text = "***该区域未发现文本***";
this.RichBoxBody_T.Text = "";
this.typeset_txt = "";
this.transtalate_fla = "关闭";
this.Trans_close.PerformClick();
base.Size = new Size((int)this.font_base.Width * 23, (int)this.font_base.Height * 24);
base.FormBorderStyle = FormBorderStyle.Sizable;
StaticValue.截图排斥 = true;
this.image_screen = StaticValue.image_OCR;
if (inihelp.GetValue("工具栏", "分栏") == "True")
{
this.minico.Visible = true;
this.thread = new Thread(new ThreadStart(this.ShowLoading));
this.thread.Start();
this.ts = new TimeSpan(DateTime.Now.Ticks);
Image image = this.image_screen;
Bitmap image2 = new Bitmap(image.Width, image.Height);
Graphics graphics = Graphics.FromImage(image2);
graphics.DrawImage(image, 0, 0, image.Width, image.Height);
graphics.Save();
graphics.Dispose();
this.image_ori = image2;
((Bitmap)this.FindBundingBox_fences((Bitmap)image)).Save("Data\\分栏预览图.jpg");
}
else
{
this.minico.Visible = true;
this.thread = new Thread(new ThreadStart(this.ShowLoading));
this.thread.Start();
this.ts = new TimeSpan(DateTime.Now.Ticks);
Messageload messageload = new Messageload();
messageload.ShowDialog();
if (messageload.DialogResult == DialogResult.OK)
{
this.esc_thread = new Thread(new ThreadStart(this.Main_OCR_Thread));
this.esc_thread.Start();
}
}
}
if (m.Msg == 786 && m.WParam.ToInt32() == 590 && this.speak_copyb == "朗读")
{
this.TTS();
return;
}
if (m.Msg == 786 && m.WParam.ToInt32() == 511)
{
base.MinimumSize = new Size((int)this.font_base.Width * 23, (int)this.font_base.Height * 24);
this.transtalate_fla = "关闭";
this.RichBoxBody.Dock = DockStyle.Fill;
this.RichBoxBody_T.Visible = false;
this.PictureBox1.Visible = false;
this.RichBoxBody_T.Text = "";
if (base.WindowState == FormWindowState.Maximized)
{
base.WindowState = FormWindowState.Normal;
}
base.Size = new Size((int)this.font_base.Width * 23, (int)this.font_base.Height * 24);
}
if (m.Msg == 786 && m.WParam.ToInt32() == 512)
{
this.transtalate_Click();
}
if (m.Msg == 786 && m.WParam.ToInt32() == 518)
{
if (base.ActiveControl.Name == "htmlTextBoxBody")
{
this.htmltxt = this.RichBoxBody.Text;
}
if (base.ActiveControl.Name == "rich_trans")
{
this.htmltxt = this.RichBoxBody_T.Text;
}
if (this.htmltxt == "")
{
return;
}
this.TTS();
}
if (m.Msg == 161)
{
HelpWin32.SetForegroundWindow(base.Handle);
base.WndProc(ref m);
return;
}
if (m.Msg != 163)
{
if (m.Msg == 786 && m.WParam.ToInt32() == 222)
{
try
{
StaticValue.截图排斥 = false;
this.esc = "退出";
this.fmloading.fml_close = "窗体已关闭";
this.esc_thread.Abort();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
base.FormBorderStyle = FormBorderStyle.Sizable;
base.Visible = true;
base.Show();
base.WindowState = FormWindowState.Normal;
if (inihelp.GetValue("快捷键", "翻译文本") != "请按下快捷键")
{
string value = inihelp.GetValue("快捷键", "翻译文本");
string text = "None";
string text2 = "F9";
this.SetHotkey(text, text2, value, 205);
}
HelpWin32.UnregisterHotKey(base.Handle, 222);
}
if (m.Msg == 786 && m.WParam.ToInt32() == 200)
{
HelpWin32.UnregisterHotKey(base.Handle, 205);
this.menu.Hide();
this.RichBoxBody.Hide = "";
this.RichBoxBody_T.Hide = "";
this.Main_OCR_Quickscreenshots();
}
if (m.Msg == 786 && m.WParam.ToInt32() == 206)
{
if (!this.fmnote.Visible || base.Focused)
{
this.fmnote.Show();
this.fmnote.WindowState = FormWindowState.Normal;
this.fmnote.Visible = true;
}
else
{
this.fmnote.Hide();
this.fmnote.WindowState = FormWindowState.Minimized;
this.fmnote.Visible = false;
}
}
if (m.Msg == 786 && m.WParam.ToInt32() == 235)
{
if (!base.Visible)
{
base.TopMost = true;
base.Show();
base.WindowState = FormWindowState.Normal;
base.Visible = true;
Thread.Sleep(100);
if (inihelp.GetValue("工具栏", "顶置") == "False")
{
base.TopMost = false;
return;
}
}
else
{
base.Hide();
base.Visible = false;
}
}
if (m.Msg == 786 && m.WParam.ToInt32() == 205)
{
this.翻译文本();
}
base.WndProc(ref m);
return;
}
if (this.transtalate_fla == "开启")
{
base.WindowState = FormWindowState.Normal;
base.Size = new Size((int)this.font_base.Width * 23 * 2, (int)this.font_base.Height * 24);
base.Location = (Point)new Size(Screen.PrimaryScreen.Bounds.Width / 2 - Screen.PrimaryScreen.Bounds.Width / 10 * 2, Screen.PrimaryScreen.Bounds.Height / 2 - Screen.PrimaryScreen.Bounds.Height / 6);
return;
}
base.WindowState = FormWindowState.Normal;
base.Location = (Point)new Size(Screen.PrimaryScreen.Bounds.Width / 2 - Screen.PrimaryScreen.Bounds.Width / 10, Screen.PrimaryScreen.Bounds.Height / 2 - Screen.PrimaryScreen.Bounds.Height / 6);
base.Size = new Size((int)this.font_base.Width * 23, (int)this.font_base.Height * 24);
return;
}
}
// Token: 0x06000063 RID: 99 RVA: 0x00002399 File Offset: 0x00000599
private void Form1_FormClosing(object sender, FormClosedEventArgs e)
{
base.WindowState = FormWindowState.Minimized;
base.Visible = false;
}
// Token: 0x06000064 RID: 100 RVA: 0x0000808C File Offset: 0x0000628C
public void InitMinimize()
{
MenuItem menuItem = new MenuItem();
MenuItem menuItem2 = new MenuItem();
new MenuItem();
MenuItem menuItem3 = new MenuItem();
MenuItem menuItem4 = new MenuItem();
new MenuItem();
MenuItem menuItem5 = new MenuItem();
try
{
MenuItem[] menuItems = new MenuItem[]
{
menuItem,
menuItem2,
menuItem3,
menuItem5,
menuItem4
};
menuItem.Text = "显示";
menuItem.Click += this.tray_show_Click;
menuItem2.Text = "设置";
menuItem2.Click += this.tray_Set_Click;
menuItem3.Text = "更新";
menuItem3.Click += this.tray_update_Click;
menuItem5.Text = "帮助";
menuItem5.Click += this.tray_help_Click;
menuItem4.Text = "退出";
menuItem4.Click += this.tray_exit_Click;
this.minico.ContextMenu = new ContextMenu(menuItems);
}
catch (Exception ex)
{
MessageBox.Show("InitMinimize()" + ex.Message);
}
}
// Token: 0x06000065 RID: 101 RVA: 0x000081B4 File Offset: 0x000063B4
private void tray_show_Click(object sender, EventArgs e)
{
base.Show();
base.Activate();
base.Visible = true;
base.WindowState = FormWindowState.Normal;
if (inihelp.GetValue("工具栏", "顶置") == "True")
{
base.TopMost = true;
return;
}
base.TopMost = false;
}
// Token: 0x06000066 RID: 102 RVA: 0x000023A9 File Offset: 0x000005A9
private void tray_exit_Click(object sender, EventArgs e)
{
this.minico.Dispose();
this.saveIniFile();
Process.GetCurrentProcess().Kill();
}
// Token: 0x06000067 RID: 103 RVA: 0x0000207C File Offset: 0x0000027C
private void setting_Click(object sender, EventArgs e)
{
}
// Token: 0x06000068 RID: 104 RVA: 0x0000207C File Offset: 0x0000027C
private void Form1_LostFocus(object sender, EventArgs e)
{
}
// Token: 0x06000069 RID: 105 RVA: 0x000023C6 File Offset: 0x000005C6
private void Main_copy_Click(object sender, EventArgs e)
{
this.RichBoxBody.Focus();
this.RichBoxBody.richTextBox1.Copy();
}
// Token: 0x0600006A RID: 106 RVA: 0x00008208 File Offset: 0x00006408
public static string punctuation_en_ch(string text)
{
char[] array = text.ToCharArray();
for (int i = 0; i < array.Length; i++)
{
int num = ":;,?!()".IndexOf(array[i]);
if (num != -1)
{
array[i] = ":;,?!()"[num];
}
}
return new string(array);
}
// Token: 0x0600006B RID: 107 RVA: 0x000023E4 File Offset: 0x000005E4
private void Main_SelectAll_Click(object sender, EventArgs e)
{
this.RichBoxBody.Focus();
this.RichBoxBody.richTextBox1.SelectAll();
}
// Token: 0x0600006C RID: 108 RVA: 0x00002402 File Offset: 0x00000602
private void Main_paste_Click(object sender, EventArgs e)
{
this.RichBoxBody.Focus();
this.RichBoxBody.richTextBox1.Paste();
}
// Token: 0x0600006D RID: 109 RVA: 0x00002420 File Offset: 0x00000620
public void Split_Click(object sender, EventArgs e)
{
this.RichBoxBody.Text = this.split_txt;
}
// Token: 0x0600006E RID: 110 RVA: 0x00008250 File Offset: 0x00006450
public static byte[] copybyte(byte[] a, byte[] b)
{
byte[] array = new byte[a.Length + b.Length];
a.CopyTo(array, 0);
b.CopyTo(array, a.Length);
return array;
}
// Token: 0x0600006F RID: 111 RVA: 0x00008280 File Offset: 0x00006480
public void OCR_sougou()
{
try
{
this.split_txt = "";
Image image = this.image_screen;
int i = image.Width;
int j = image.Height;
if (i < 300)
{
while (i < 300)
{
j *= 2;
i *= 2;
}
}
if (j < 120)
{
while (j < 120)
{
j *= 2;
i *= 2;
}
}
Bitmap bitmap = new Bitmap(i, j);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.DrawImage(image, 0, 0, i, j);
graphics.Save();
graphics.Dispose();
JArray jarray = JArray.Parse(((JObject)JsonConvert.DeserializeObject(this.OCR_sougou_SogouOCR(bitmap)))["result"].ToString());
bitmap.Dispose();
this.checked_txt(jarray, 2, "content");
}
catch
{
if (this.esc != "退出")
{
this.RichBoxBody.Text = "***该区域未发现文本***";
}
else
{
this.RichBoxBody.Text = "***该区域未发现文本***";
this.esc = "";
}
}
}
// Token: 0x06000070 RID: 112 RVA: 0x00008390 File Offset: 0x00006590
public byte[] ImageTobyte(Image imgPhoto)
{
MemoryStream memoryStream = new MemoryStream();
imgPhoto.Save(memoryStream, ImageFormat.Jpeg);
byte[] array = new byte[memoryStream.Length];
memoryStream.Position = 0L;
memoryStream.Read(array, 0, array.Length);
memoryStream.Close();
return array;
}
// Token: 0x06000071 RID: 113 RVA: 0x000083D8 File Offset: 0x000065D8
private Bitmap GetPlus(Bitmap bm, double times)
{
int width = (int)((double)bm.Width / times);
int height = (int)((double)bm.Height / times);
Bitmap bitmap = new Bitmap(width, height);
if (times >= 1.0 && times <= 1.1)
{
bitmap = bm;
}
else
{
Graphics graphics = Graphics.FromImage(bitmap);
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.DrawImage(bm, new Rectangle(0, 0, width, height), new Rectangle(0, 0, bm.Width, bm.Height), GraphicsUnit.Pixel);
graphics.Dispose();
}
return bitmap;
}
// Token: 0x06000072 RID: 114 RVA: 0x00008464 File Offset: 0x00006664
public void OCR_Tencent()
{
try
{
this.split_txt = "";
string text = "------WebKitFormBoundaryRDEqU0w702X9cWPJ";
Image image = this.image_screen;
if (image.Width > 90 && image.Height < 90)
{
Bitmap bitmap = new Bitmap(image.Width, 300);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.DrawImage(image, 5, 0, image.Width, image.Height);
graphics.Save();
graphics.Dispose();
image = new Bitmap(bitmap);
}
else if (image.Width <= 90 && image.Height >= 90)
{
Bitmap bitmap2 = new Bitmap(300, image.Height);
Graphics graphics2 = Graphics.FromImage(bitmap2);
graphics2.DrawImage(image, 0, 5, image.Width, image.Height);
graphics2.Save();
graphics2.Dispose();
image = new Bitmap(bitmap2);
}
else if (image.Width < 90 && image.Height < 90)
{
Bitmap bitmap3 = new Bitmap(300, 300);
Graphics graphics3 = Graphics.FromImage(bitmap3);
graphics3.DrawImage(image, 5, 5, image.Width, image.Height);
graphics3.Save();
graphics3.Dispose();
image = new Bitmap(bitmap3);
}
else
{
image = this.image_screen;
}
byte[] b = this.OCR_ImgToByte(image);
string s = text + "\r\nContent-Disposition: form-data; name=\"image_file\"; filename=\"pic.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n";
string s2 = "\r\n" + text + "--\r\n";
byte[] bytes = Encoding.ASCII.GetBytes(s);
byte[] bytes2 = Encoding.ASCII.GetBytes(s2);
byte[] array = FmMain.Mergebyte(bytes, b, bytes2);
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://ai.qq.com/cgi-bin/appdemo_generalocr");
httpWebRequest.Method = "POST";
httpWebRequest.Referer = "http://ai.qq.com/product/ocr.shtml";
httpWebRequest.Headers.Add("Accept-Encoding", "gzip,deflate");
httpWebRequest.ContentType = "multipart/form-data; boundary=" + text.Substring(2);
httpWebRequest.Timeout = 8000;
httpWebRequest.ReadWriteTimeout = 2000;
byte[] buffer = array;
using (Stream requestStream = httpWebRequest.GetRequestStream())
{
requestStream.Write(buffer, 0, array.Length);
}
Stream responseStream = ((HttpWebResponse)httpWebRequest.GetResponse()).GetResponseStream();
string value = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")).ReadToEnd();
responseStream.Close();
JArray jarray = JArray.Parse(((JObject)JsonConvert.DeserializeObject(value))["data"]["item_list"].ToString());
this.checked_txt(jarray, 1, "itemstring");
}
catch
{
if (this.esc != "退出")
{
this.RichBoxBody.Text = "***该区域未发现文本***";
}
else
{
this.RichBoxBody.Text = "***该区域未发现文本***";
this.esc = "";
}
}
}
// Token: 0x06000073 RID: 115 RVA: 0x0000874C File Offset: 0x0000694C
public void OCR_baidu_bak()
{
this.split_txt = "";
try
{
string str = "CHN_ENG";
this.split_txt = "";
Image image = this.image_screen;
MemoryStream memoryStream = new MemoryStream();
image.Save(memoryStream, ImageFormat.Jpeg);
byte[] array = new byte[memoryStream.Length];
memoryStream.Position = 0L;
memoryStream.Read(array, 0, (int)memoryStream.Length);
memoryStream.Close();
if (this.interface_flag == "中英")
{
str = "CHN_ENG";
}
if (this.interface_flag == "日语")
{
str = "JAP";
}
if (this.interface_flag == "韩语")
{
str = "KOR";
}
string s = "type=general_location&image=data" + HttpUtility.UrlEncode(":image/jpeg;base64," + Convert.ToBase64String(array)) + "&language_type=" + str;
byte[] bytes = Encoding.UTF8.GetBytes(s);
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://ai.baidu.com/tech/ocr/general");
httpWebRequest.CookieContainer = new CookieContainer();
httpWebRequest.GetResponse().Close();
HttpWebRequest httpWebRequest2 = (HttpWebRequest)WebRequest.Create("http://ai.baidu.com/aidemo");
httpWebRequest2.Method = "POST";
httpWebRequest2.Referer = "http://ai.baidu.com/tech/ocr/general";
httpWebRequest2.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
httpWebRequest2.Timeout = 8000;
httpWebRequest2.ReadWriteTimeout = 5000;
httpWebRequest2.Headers.Add("Cookie:" + FmMain.CookieCollectionToStrCookie(((HttpWebResponse)httpWebRequest.GetResponse()).Cookies));
using (Stream requestStream = httpWebRequest2.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
}
Stream responseStream = ((HttpWebResponse)httpWebRequest2.GetResponse()).GetResponseStream();
string value = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")).ReadToEnd();
responseStream.Close();
JArray jarray = JArray.Parse(((JObject)JsonConvert.DeserializeObject(value))["data"]["words_result"].ToString());
string str2 = "";
string str3 = "";
for (int i = 0; i < jarray.Count; i++)
{
JObject jobject = JObject.Parse(jarray[i].ToString());
char[] array2 = jobject["words"].ToString().ToCharArray();
if (!char.IsPunctuation(array2[array2.Length - 1]))
{
if (!FmMain.contain_ch(jobject["words"].ToString()))
{
str3 = str3 + jobject["words"].ToString().Trim() + " ";
}
else
{
str3 += jobject["words"].ToString();
}
}
else if (this.own_punctuation(array2[array2.Length - 1].ToString()))
{
if (!FmMain.contain_ch(jobject["words"].ToString()))
{
str3 = str3 + jobject["words"].ToString().Trim() + " ";
}
else
{
str3 += jobject["words"].ToString();
}
}
else
{
str3 = str3 + jobject["words"].ToString() + "\r\n";
}
str2 = str2 + jobject["words"].ToString() + "\r\n";
}
this.split_txt = str2;
this.typeset_txt = str3;
}
catch
{
if (this.esc != "退出")
{
this.RichBoxBody.Text = "***该区域未发现文本***";
}
else
{
this.RichBoxBody.Text = "***该区域未发现文本***";
this.esc = "";
}
}
}
// Token: 0x06000074 RID: 116 RVA: 0x00002433 File Offset: 0x00000633
private void OCR_sougou_Click(object sender, EventArgs e)
{
this.OCR_foreach("搜狗");
}
// Token: 0x06000075 RID: 117 RVA: 0x00002440 File Offset: 0x00000640
private void OCR_tencent_Click(object sender, EventArgs e)
{
this.OCR_foreach("腾讯");
}
// Token: 0x06000076 RID: 118 RVA: 0x0000207C File Offset: 0x0000027C
private void OCR_baidu_Click(object sender, EventArgs e)
{
}
// Token: 0x06000077 RID: 119 RVA: 0x00008B54 File Offset: 0x00006D54
public void OCR_youdao()
{
try
{
this.split_txt = "";
Image image = this.image_screen;
if (image.Width > 90 && image.Height < 90)
{
Bitmap bitmap = new Bitmap(image.Width, 200);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.DrawImage(image, 5, 0, image.Width, image.Height);
graphics.Save();
graphics.Dispose();
image = new Bitmap(bitmap);
}
else if (image.Width <= 90 && image.Height >= 90)
{
Bitmap bitmap2 = new Bitmap(200, image.Height);
Graphics graphics2 = Graphics.FromImage(bitmap2);
graphics2.DrawImage(image, 0, 5, image.Width, image.Height);
graphics2.Save();
graphics2.Dispose();
image = new Bitmap(bitmap2);
}
else if (image.Width < 90 && image.Height < 90)
{
Bitmap bitmap3 = new Bitmap(200, 200);
Graphics graphics3 = Graphics.FromImage(bitmap3);
graphics3.DrawImage(image, 5, 5, image.Width, image.Height);
graphics3.Save();
graphics3.Dispose();
image = new Bitmap(bitmap3);
}
else
{
image = this.image_screen;
}
int i = image.Width;
int j = image.Height;
if (i < 600)
{
while (i < 600)
{
j *= 2;
i *= 2;
}
}
if (j < 120)
{
while (j < 120)
{
j *= 2;
i *= 2;
}
}
Bitmap bitmap4 = new Bitmap(i, j);
Graphics graphics4 = Graphics.FromImage(bitmap4);
graphics4.DrawImage(image, 0, 0, i, j);
graphics4.Save();
graphics4.Dispose();
image = new Bitmap(bitmap4);
byte[] inArray = this.OCR_ImgToByte(image);
string s = "imgBase=data" + HttpUtility.UrlEncode(":image/jpeg;base64," + Convert.ToBase64String(inArray)) + "&lang=auto&company=";
byte[] bytes = Encoding.UTF8.GetBytes(s);
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://aidemo.youdao.com/ocrapi1");
httpWebRequest.Method = "POST";
httpWebRequest.Referer = "http://aidemo.youdao.com/ocrdemo";
httpWebRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
httpWebRequest.Timeout = 8000;
httpWebRequest.ReadWriteTimeout = 2000;
using (Stream requestStream = httpWebRequest.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
}
Stream responseStream = ((HttpWebResponse)httpWebRequest.GetResponse()).GetResponseStream();
string value = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")).ReadToEnd();
responseStream.Close();
JArray jarray = JArray.Parse(((JObject)JsonConvert.DeserializeObject(value))["lines"].ToString());
this.checked_txt(jarray, 1, "words");
image.Dispose();
}
catch
{
if (this.esc != "退出")
{
this.RichBoxBody.Text = "***该区域未发现文本***";
}
else
{
this.RichBoxBody.Text = "***该区域未发现文本***";
this.esc = "";
}
}
}
// Token: 0x06000078 RID: 120 RVA: 0x0000244D File Offset: 0x0000064D
public void OCR_youdao_Click(object sender, EventArgs e)
{
this.OCR_foreach("有道");
}
// Token: 0x06000079 RID: 121 RVA: 0x00008E64 File Offset: 0x00007064
public void change_Chinese_Click(object sender, EventArgs e)
{
this.language = "中文标点";
if (this.typeset_txt != "")
{
this.RichBoxBody.Text = FmMain.punctuation_en_ch_x(this.RichBoxBody.Text);
this.RichBoxBody.Text = this.punctuation_quotation(this.RichBoxBody.Text);
}
}
// Token: 0x0600007A RID: 122 RVA: 0x0000245A File Offset: 0x0000065A
public void change_English_Click(object sender, EventArgs e)
{
this.language = "英文标点";
if (this.typeset_txt != "")
{
this.RichBoxBody.Text = FmMain.punctuation_ch_en(this.RichBoxBody.Text);
}
}
// Token: 0x0600007B RID: 123 RVA: 0x00008EC8 File Offset: 0x000070C8
public static string punctuation_ch_en(string text)
{
char[] array = text.ToCharArray();
for (int i = 0; i < array.Length; i++)
{
int num = ":。;,?!“”‘’【】()".IndexOf(array[i]);
if (num != -1)
{
array[i] = ":.;,?!\"\"''[]()"[num];
}
}
return new string(array);
}
// Token: 0x0600007C RID: 124 RVA: 0x00002494 File Offset: 0x00000694
public void saveIniFile()
{
inihelp.SetValue("配置", "接口", this.interface_flag);
}
// Token: 0x0600007D RID: 125 RVA: 0x00008F10 File Offset: 0x00007110
public void readIniFile()
{
this.Proxy_flag = inihelp.GetValue("代理", "代理类型");
this.Proxy_url = inihelp.GetValue("代理", "服务器");
this.Proxy_port = inihelp.GetValue("代理", "端口");
this.Proxy_name = inihelp.GetValue("代理", "服务器账号");
this.Proxy_password = inihelp.GetValue("代理", "服务器密码");
if (this.Proxy_flag == "不使用代理")
{
WebRequest.DefaultWebProxy = null;
}
if (this.Proxy_flag == "系统代理")
{
WebRequest.DefaultWebProxy = WebRequest.GetSystemWebProxy();
}
if (this.Proxy_flag == "自定义代理")
{
try
{
WebProxy webProxy = new WebProxy(this.Proxy_url, Convert.ToInt32(this.Proxy_port));
if (this.Proxy_name != "" && this.Proxy_password != "")
{
ICredentials credentials = new NetworkCredential(this.Proxy_name, this.Proxy_password);
webProxy.Credentials = credentials;
}
WebRequest.DefaultWebProxy = webProxy;
}
catch
{
MessageBox.Show("请检查代理设置!");
}
}
this.interface_flag = inihelp.GetValue("配置", "接口");
if (this.interface_flag == "发生错误")
{
inihelp.SetValue("配置", "接口", "搜狗");
this.OCR_foreach("搜狗");
}
else
{
this.OCR_foreach(this.interface_flag);
}
string filePath = AppDomain.CurrentDomain.BaseDirectory + "Data\\config.ini";
if (inihelp.GetValue("快捷键", "文字识别") != "请按下快捷键")
{
string value = inihelp.GetValue("快捷键", "文字识别");
string text = "None";
string text2 = "F4";
this.SetHotkey(text, text2, value, 200);
}
if (inihelp.GetValue("快捷键", "翻译文本") != "请按下快捷键")
{
string value2 = inihelp.GetValue("快捷键", "翻译文本");
string text3 = "None";
string text4 = "F7";
this.SetHotkey(text3, text4, value2, 205);
}
if (inihelp.GetValue("快捷键", "记录界面") != "请按下快捷键")
{
string value3 = inihelp.GetValue("快捷键", "记录界面");
string text5 = "None";
string text6 = "F8";
this.SetHotkey(text5, text6, value3, 206);
}
if (inihelp.GetValue("快捷键", "识别界面") != "请按下快捷键")
{
string value4 = inihelp.GetValue("快捷键", "识别界面");
string text7 = "None";
string text8 = "F11";
this.SetHotkey(text7, text8, value4, 235);
}
StaticValue.baiduAPI_ID = HelpWin32.IniFileHelper.GetValue("密钥_百度", "secret_id", filePath);
if (HelpWin32.IniFileHelper.GetValue("密钥_百度", "secret_id", filePath) == "发生错误")
{
StaticValue.baiduAPI_ID = "请输入secret_id";
}
StaticValue.baiduAPI_key = HelpWin32.IniFileHelper.GetValue("密钥_百度", "secret_key", filePath);
if (HelpWin32.IniFileHelper.GetValue("密钥_百度", "secret_key", filePath) == "发生错误")
{
StaticValue.baiduAPI_key = "请输入secret_key";
}
}
// Token: 0x0600007E RID: 126 RVA: 0x00009250 File Offset: 0x00007450
public static string check_ch_en(string text)
{
char[] array = text.ToCharArray();
for (int i = 0; i < array.Length; i++)
{
int num = ":".IndexOf(array[i]);
if (num != -1 && i - 1 >= 0 && i + 1 < array.Length && FmMain.contain_en(array[i - 1].ToString()) && FmMain.contain_en(array[i + 1].ToString()))
{
array[i] = ":"[num];
}
if (num != -1 && i - 1 >= 0 && i + 1 < array.Length && FmMain.contain_en(array[i - 1].ToString()) && FmMain.contain_punctuation(array[i + 1].ToString()))
{
array[i] = ":"[num];
}
}
return new string(array);
}
// Token: 0x0600007F RID: 127 RVA: 0x00009320 File Offset: 0x00007520
public void tray_Set_Click(object sender, EventArgs e)
{
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
HelpWin32.UnregisterHotKey(base.Handle, 200);
HelpWin32.UnregisterHotKey(base.Handle, 205);
HelpWin32.UnregisterHotKey(base.Handle, 206);
HelpWin32.UnregisterHotKey(base.Handle, 235);
base.WindowState = FormWindowState.Minimized;
FmSetting fmSetting = new FmSetting();
fmSetting.TopMost = true;
fmSetting.ShowDialog();
if (fmSetting.DialogResult == DialogResult.OK)
{
string filePath = AppDomain.CurrentDomain.BaseDirectory + "Data\\config.ini";
StaticValue.v_notecount = Convert.ToInt32(HelpWin32.IniFileHelper.GetValue("配置", "记录数目", filePath));
this.pubnote = new string[StaticValue.v_notecount];
for (int i = 0; i < StaticValue.v_notecount; i++)
{
this.pubnote[i] = "";
}
StaticValue.v_note = this.pubnote;
this.fmnote.Text_note_change = "";
this.fmnote.Location = new Point(Screen.AllScreens[0].WorkingArea.Width - this.fmnote.Width, Screen.AllScreens[0].WorkingArea.Height - this.fmnote.Height);
if (inihelp.GetValue("快捷键", "文字识别") != "请按下快捷键")
{