Color secondTransTextColor; //第二翻译源结果颜色 /// <summary> /// UI初始化、翻译API初始化、如果是OCR模式则Hook鼠标点击事件 /// </summary> private void InitUI() { srcTextLabel = new Label(); srcTextLabel.AutoSize = false; srcTextLabel.Text = "等待源文本"; srcTextLabel.BackColor = TransparencyColor; //背景色透明 srcTextLabel.TextAlign = ContentAlignment.TopLeft; firstTransTextLabel = new Label(); firstTransTextLabel.AutoSize = false; firstTransTextLabel.Text = "等待源文本"; firstTransTextLabel.BackColor = TransparencyColor; //背景色透明 firstTransTextLabel.TextAlign = ContentAlignment.TopLeft; secondTransTextLabel = new Label(); secondTransTextLabel.AutoSize = false; secondTransTextLabel.Text = "等待源文本"; secondTransTextLabel.BackColor = TransparencyColor; //背景色透明 secondTransTextLabel.TextAlign = ContentAlignment.TopLeft; LabelInit(); this.Controls.Add(srcTextLabel); this.Controls.Add(firstTransTextLabel); this.Controls.Add(secondTransTextLabel); this.FormBorderStyle = FormBorderStyle.None; this.SizeChanged += GameTranslateForm_SizeChanged; this.FormClosing += GameTranslateForm_FormClosing; BaiduTranslator.BaiduTrans_Init(); TencentTranslator.TencentTrans_Init(); TencentOldTranslator.TencentOldTrans_Init(); if (Common.TransMode == 2) { BaiduGeneralOCRBasic.BaiduGeneralOCRBasic_Init(); //初始化钩子对象 if (hook == null) { hook = new GlobalMouseHook(); hook.OnMouseActivity += new MouseEventHandler(Hook_OnMouseActivity); } IsOCRingFlag = false; bool r = hook.Start(); if (r == false) { MessageBox.Show("安装钩子失败!"); } } TextFontColorInit(); firstTransAPI = IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "Translate_All", "FirstTranslator", "NoTranslate"); secondTransAPI = IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "Translate_All", "SecondTranslator", "NoTranslate"); }
private void TestOCRBtn_BtnClick(object sender, EventArgs e) { BaiduGeneralOCRBasic.BaiduGeneralOCRBasic_Init(); Image img = ScreenCapture.GetWindowRectCapture((IntPtr)SelectedHwnd, Common.OCRrec, Common.isAllWindowCap); string ret = BaiduGeneralOCRBasic.BaiduGeneralBasicOCR(img, srcLangCombox.SelectedValue); MessageBox.Show(ret, "百度OCR结果"); }
private void BaiduOCRTestBtn_BtnClick(object sender, EventArgs e) { IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "BaiduOCR", "APIKEY", BDOCRapikeyTextBox.InputText); IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "BaiduOCR", "SecretKey", BDOCRsecretkeyTextBox.InputText); bool ret = BaiduGeneralOCRBasic.BaiduGeneralOCRBasic_Init(); if (ret == true) { MessageBox.Show("百度OCR API工作正常", "提示"); } else { MessageBox.Show("百度OCR API工作异常,请检查填写是否正确", "错误"); } }
private void BaiduOCRTestBtn_BtnClick(object sender, EventArgs e) { Common.settings.BDOCR_APIKEY = BDOCRapikeyTextBox.InputText; Common.settings.BDOCR_SecretKey = BDOCRsecretkeyTextBox.InputText; bool ret = BaiduGeneralOCRBasic.BaiduGeneralOCRBasic_Init(); if (ret == true) { MessageBox.Show("百度OCR API工作正常", "提示"); } else { MessageBox.Show("百度OCR API工作异常,请检查填写是否正确", "错误"); } }
private void TestOCRBtn_BtnClick(object sender, EventArgs e) { srcPic = (Bitmap)ScreenCapture.GetWindowRectCapture((IntPtr)SelectedHwnd, Common.OCRrec, Common.isAllWindowCap); if (srcPic == null) { MessageBox.Show("请选择正确的截屏区域", "警告"); return; } Bitmap bm; if (PreHandleCheckBox.Checked == true) { TesseractOCR.thresh = (int)threshTrackBar.Value; bm = TesseractOCR.Thresholding(srcPic); } else { bm = srcPic; } if (Common.settings.OCRsource == "BaiduOCR") { BaiduGeneralOCRBasic.BaiduGeneralOCRBasic_Init(); string ret = BaiduGeneralOCRBasic.BaiduGeneralBasicOCR(bm, srcLangCombox.SelectedValue); MessageBox.Show(ret, "百度OCR结果"); } else { if (srcLangCombox.SelectedValue == "JAP") { TesseractOCR.srcLangCode = "jpn"; } else if (srcLangCombox.SelectedValue == "ENG") { TesseractOCR.srcLangCode = "eng"; } TesseractOCR.TesseractOCR_Init(); string ret = TesseractOCR.OCRProcess(bm); MessageBox.Show(ret, "Tesseract离线OCR结果"); } }
Color secondTransTextColor; //第二翻译源结果颜色 /// <summary> /// UI初始化、翻译API初始化、如果是OCR模式则Hook鼠标点击事件 /// </summary> private void InitUI() { srcTextLabel = new Label(); srcTextLabel.AutoSize = false; srcTextLabel.Text = "等待源文本"; srcTextLabel.BackColor = TransparencyColor; //背景色透明 srcTextLabel.TextAlign = ContentAlignment.TopLeft; firstTransTextLabel = new Label(); firstTransTextLabel.AutoSize = false; firstTransTextLabel.Text = "等待源文本"; firstTransTextLabel.BackColor = TransparencyColor; //背景色透明 firstTransTextLabel.TextAlign = ContentAlignment.TopLeft; secondTransTextLabel = new Label(); secondTransTextLabel.AutoSize = false; secondTransTextLabel.Text = "等待源文本"; secondTransTextLabel.BackColor = TransparencyColor; //背景色透明 secondTransTextLabel.TextAlign = ContentAlignment.TopLeft; LabelInit(); this.Controls.Add(srcTextLabel); this.Controls.Add(firstTransTextLabel); this.Controls.Add(secondTransTextLabel); this.FormBorderStyle = FormBorderStyle.None; this.SizeChanged += GameTranslateForm_SizeChanged; this.FormClosing += GameTranslateForm_FormClosing; BaiduTranslator.BaiduTrans_Init(); TencentTranslator.TencentTrans_Init(); TencentOldTranslator.TencentOldTrans_Init(); if (Common.TransMode == 2) { if (Common.settings.OCRsource == "BaiduOCR") { BaiduGeneralOCRBasic.BaiduGeneralOCRBasic_Init(); } else { TesseractOCR.TesseractOCR_Init(); } //初始化钩子对象 if (hook == null) { hook = new GlobalMouseHook(); hook.OnMouseActivity += new MouseEventHandler(Hook_OnMouseActivity); } IsOCRingFlag = false; bool r = hook.Start(); if (r == false) { MessageBox.Show("安装钩子失败!"); } } TextFontColorInit(); firstTransAPI = Common.settings.FirstTranslator; secondTransAPI = Common.settings.SecondTranslator; }