private void ButtonCutPic_Click(object sender, EventArgs e) { if (Setting.FormHide) { this.Visible = false; // 截图时隐藏本窗体 System.Threading.Thread.Sleep(200); // 延时,避免把本窗体也截下来 } ShowCutPic(); this.Visible = true; this.WindowState = FormWindowState.Normal; this.Activate(); Application.DoEvents(); // DoEvents()将强制处理消息队列中的所有消息 try { if (Clipboard.ContainsImage()) { ButtonPart.Text = "自动分段"; Image img = Clipboard.GetImage(); // 获取剪切板图片 RichTextBoxValue.Text = OCRHelper.BaiduBasic("", img).Trim(); // 识别剪切板图片的文字 if (Setting.TextCopy) { ButtonCopy_Click(null, null); } } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "错误"); } }
private void ButtonCutPic_Click(object sender, EventArgs e) { this.Visible = false; System.Threading.Thread.Sleep(200); ShowCutPic(); try { if (Clipboard.ContainsImage()) { ButtonPart.BackgroundImage = 自动分段ToolStripMenuItem.Image; toolTip1.SetToolTip(ButtonPart, "自动分段"); Image img = Clipboard.GetImage(); RichTextBoxValue.Text = OCRHelper.BaiduBasic("", img); this.Visible = true; } else { this.Visible = true; } } catch (Exception ex) { this.Visible = true; MessageBox.Show(this, ex.Message, "错误"); } }
private void ResultOutput(string path, Image img = null) { if (img == null) { OCRHelper.BaiduBasic(path); } else { OCRHelper.BaiduBasic("", img); } // 段落 switch (Setting.Paragraph) { case 1: RichTextBoxValue.Text = OCRHelper.typeset_txt.Trim(); break; case 2: RichTextBoxValue.Text = OCRHelper.split_txt.Trim(); break; case 3: RichTextBoxValue.Text = OCRHelper.typeset_txt.Trim().Replace("\n", "").Replace("\r", ""); break; } // 识别后自动复制 if (Setting.TextCopy) { ButtonCopy_Click(null, null); } }
private void ButtonFile_Click(object sender, EventArgs e) { openFileDialog1.Filter = "图片文件 (*.jpg,*.jpeg,*.png,*.bmp)|*.jgp;*.jpeg;*.png;*.bmp;"; //设置多文件格式 if (this.openFileDialog1.ShowDialog() == DialogResult.OK) { ButtonPart.BackgroundImage = 自动分段ToolStripMenuItem.Image; RichTextBoxValue.Text = OCRHelper.BaiduBasic(openFileDialog1.FileName); } }
private void ResultOutput(int type, string path, Image img = null) { if (Setting.IsOffline) { RichTextBoxValue.Text = OCROffline.OCROffile(path, img); } else { // 文字识别 if (type == 1) { if (img == null) { OCRHelper.BaiduBasic(path); } else { OCRHelper.BaiduBasic("", img); } // 段落 switch (Setting.Paragraph) { case 1: RichTextBoxValue.Text = OCRHelper.typeset_txt.Trim(); break; case 2: RichTextBoxValue.Text = OCRHelper.split_txt.Trim(); break; case 3: RichTextBoxValue.Text = OCRHelper.typeset_txt.Trim().Replace("\n", "").Replace("\r", ""); break; } } else // 表格识别 { if (img == null) { RichTextBoxValue.Text = OCRHelper.BaiduForm(path); } else { RichTextBoxValue.Text = OCRHelper.BaiduForm("", img); } } } // 识别后自动复制 if (Setting.TextCopy) { ButtonCopy_Click(null, null); } }
private void ButtonFile_Click(object sender, EventArgs e) { openFileDialog1.Filter = "图片文件 (*.jpg,*.jpeg,*.png,*.bmp)|*.jgp;*.jpeg;*.png;*.bmp;"; //设置多文件格式 if (this.openFileDialog1.ShowDialog() == DialogResult.OK) { ButtonPart.Text = "自动分段"; RichTextBoxValue.Text = OCRHelper.BaiduBasic(openFileDialog1.FileName).Trim(); if (Setting.TextCopy) { ButtonCopy_Click(null, null); } } }
private void FormMain_DragDrop(object sender, DragEventArgs e) { try { ButtonPart.BackgroundImage = 自动分段ToolStripMenuItem.Image; string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); RichTextBoxValue.Text = OCRHelper.BaiduBasic(path); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "错误"); } }
private void FormMain_DragDrop(object sender, DragEventArgs e) { try { ButtonPart.Text = "自动分段"; string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); RichTextBoxValue.Text = OCRHelper.BaiduBasic(path).Trim(); if (Setting.TextCopy) { ButtonCopy_Click(null, null); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "错误"); } }
private void ButtonCutPic_Click(object sender, EventArgs e) { this.Visible = false; // 截图时隐藏本窗体 System.Threading.Thread.Sleep(200); // 延时,避免把本窗体也截下来 ShowCutPic(); // 截图功能 this.Visible = true; Application.DoEvents(); // DoEvents()将强制处理消息队列中的所有消息 try { if (Clipboard.ContainsImage()) { ButtonPart.BackgroundImage = 自动分段ToolStripMenuItem.Image; toolTip1.SetToolTip(ButtonPart, "自动分段"); Image img = Clipboard.GetImage(); // 获取剪切板图片 RichTextBoxValue.Text = OCRHelper.BaiduBasic("", img); // 识别剪切板图片的文字 } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "错误"); } }