C#如何提取图片上的文字
我在网上搜到了有两种方法,
1、using XDICTGRB;
public partial class Form1 : Form, IXDictGrabSink
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern int SetWindowPos
(
IntPtr hwnd,
int hWndInsertAfter,
int x,
int y,
int cx,
int cy,
int wFlags
);
private void Form1_Load(object sender, EventArgs e)
{
SetWindowPos(this.Handle, -1, Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2, this.Width, this.Height, 0);
int i;
GrabProxy gp = new GrabProxy();//取词代理对象
gp.GrabInterval = 1;//指抓取时间间隔
gp.GrabMode = XDictGrabModeEnum.XDictGrabMouse;//设定取词的属性
gp.GrabFlag = (XDictGrabFlagEnum.XDictGrabDisableButton & XDictGrabFlagEnum.XDictGrabDisableMenu & XDictGrabFlagEnum.XDictGrabDisableCaption);
gp.GrabEnabled = true;//是否取词的属性
i = gp.AdviseGrab(this);
}
int IXDictGrabSink.QueryWord(string WordString, int lCursorX, int lCursorY, string SentenceString, ref int lLoc, ref int lStart)
{
this.textBox4.Text = SentenceString;//鼠标所在语句
return 1;
}
//取得单词的Method
private string GetWord(string SentenceString, int lLoc)
{
int iR = 0;
int iL = 0;
int ilen = 0;
ilen = SentenceString.Length;
String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (iL = lLoc; iL > 0; iL--)
{
if (str.IndexOf(SentenceString.Substring(iL, 1)) == -1)
break;
}
for (iR = lLoc; iR < ilen; iR++)
{
if (str.IndexOf(SentenceString.Substring(iR, 1)) == -1)
break;
}
return SentenceString.Substring(iL + 1, iR - iL - 1);
}
然后呢? 这些方法我能看懂一点,但是怎么调用呢?
2、nhw32.dll
class Program
{
[DllImport(@"C:/WINDOWS/system32\nhw32.dll")]
private static extern uint BL_SetFlag32(uint nFlag, IntPtr hNotifyWnd, int MouseX, int MouseY);
[DllImport(@"C:/WINDOWS/system32\nhw32.dll")]
private static extern uint BL_GetText32([MarshalAs(UnmanagedType.LPStr)]StringBuilder lpszCurWord, int nBufferSize, ref Rectangle lpWordRect);
[DllImport(@"C:/WINDOWS/system32\nhw32.dll")]
private static extern bool SetNHW32();
static void Main(string[] args)
{
int bufSize = 256;
StringBuilder sb = new StringBuilder(bufSize);
Rectangle rect = new Rectangle(0, 0, 100, 100);
if (SetNHW32())
{
BL_SetFlag32(1001, IntPtr.Zero, 100, 100);
BL_GetText32(sb, bufSize, ref rect);
}
Console.ReadLine();
}
这个是我在网上复制的C:/WINDOWS/system32\nhw32.dll 我在电脑里找了半天也没找到nhw32.dll,要下载么?
请高手指点,还有 网上很多人说用orc,那怎么用呢? 能不能具体点。俯身倾耳以请