基本信息
源码名称:图像文字识别(Interop.MODI)
源码大小:0.20M
文件格式:.rar
开发语言:C#
更新时间:2016-07-01
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Windows; using System.Drawing.Imaging; using System.Threading; namespace DevOCR { public partial class Form1 : Form { // Declare the two dialog objects // we'll be using. //声明的两个对话框对象 //我们将使用。 MyWin m_WindowDlg; ShowBitmap m_ShowBitmapDlg; public Form1() { InitializeComponent(); } private void btnCapture_Click(object sender, EventArgs e) { // Get the screen width and height.获取屏幕的宽度和高度。 int w = Screen.PrimaryScreen.Bounds.Width; int h = Screen.PrimaryScreen.Bounds.Height; // Create the dialog object on which we'll创建对话框对象上,我们将 // display the screen bitmap.在屏幕显示位图。 m_WindowDlg = new MyWin(); // Set to wait cursor so user knows something设置为等待光标,使用户知道的东西 // is going on.是怎么回事。 Cursor = Cursors.WaitCursor; // Hide the main app window so that it isn't in the隐藏在主应用程序窗口,以便它不是在 // capture image (and wait since Vista takes its time).捕获图像(等待由于Vista需要的时间)。 Hide(); Thread.Sleep(200); // Create the bitmap into which the screen will be copied.创建到该屏幕将被复制位图。 m_WindowDlg.m_objBitmap = new Bitmap(w, h, PixelFormat.Format32bppArgb); // Get the graphics context for the bitmap.获取为位图图形上下文。 Graphics g = Graphics.FromImage(m_WindowDlg.m_objBitmap); // Copy the screen into the bitmap object.位图复制到对象的屏幕。 g.CopyFromScreen(0, 0, 0, 0, new Size(w, h)); // Show the main application window. We need显示主应用程序窗口。我们需要 // to do this because the child window won't这样做,因为子窗口不会 // behave properly if it's hidden or minimized.循规蹈矩,如果是隐藏或最小化。 Show(); // Create a delegate so that the EndCapture创建一个代表,让EndCapture // method can be called.方法可以调用。 m_WindowDlg.m_EndCaptureMethod = new MyWin.EndCaptureMethod(EndCapture); // Show the captured screen.查看捕获的屏幕。 m_WindowDlg.Show(); // Hide the main application window.隐藏主应用程序窗口。 Hide(); // Set the location, size, and cursor of the设置的位置,大小,以及游标 // dialog in which the user will select对话框中,用户将选择 // a portion.的一部分。 m_WindowDlg.Location = new Point(0, 0); m_WindowDlg.Size = new Size(w, h); m_WindowDlg.Cursor = Cursors.Cross; } // This method is called once the user is这种方法被称为一旦用户 // finished selecting the screen region完成选择屏幕区域 // that will be OCRed.将文本识别过。 public void EndCapture(int x, int y, int w, int h) { // Restore cursor恢复光标 Cursor = Cursors.Default; // Created the dialog in which we'll创建对话框中,我们将 // show the capture bitmap.显示位图的捕获。 m_ShowBitmapDlg = new ShowBitmap(); // Copy the bitmap from the selection bitmap复制从选择位图位图 // that was displayed to the display bitmap.这是显示在显示位图。 m_ShowBitmapDlg.m_objBitmap = new Bitmap(w, h, PixelFormat.Format32bppArgb); // Get the graphics context for the bitmap.获取为位图图形上下文 Graphics g = Graphics.FromImage(m_ShowBitmapDlg.m_objBitmap); // Copy the selected portion into the newly-created选定部分复制到新创建的 // bitmap.位图 g.DrawImage(m_WindowDlg.m_objBitmap, new Rectangle(0, 0, w, h), x, y, w, h, GraphicsUnit.Pixel); // Hide the dialog that was used to display the 隐藏了用来显示对话框 // entire screen.整个屏幕。 m_WindowDlg.Hide(); // Add to the width and height the frame margins.增加宽度和高度的框架边缘 w = (m_ShowBitmapDlg.Bounds.Width - m_ShowBitmapDlg.ClientRectangle.Width); h = (m_ShowBitmapDlg.Bounds.Height - m_ShowBitmapDlg.ClientRectangle.Height); // Set the maximum size for the window in which设置的窗口,其中最大尺寸 // we'll display the bitmap.我们将会显示位图。 m_ShowBitmapDlg.MaximumSize = m_ShowBitmapDlg.Size = new Size(w, h); // Show the bitmap in the dialog.查看对话框中的位图。 m_ShowBitmapDlg.ShowDialog(); // Now re-show the main application window.现在重新出现在主应用程序窗口。 Show(); } } }