C#如何提取图片上的文字

抢不到就去偷 2015-12-24 12:48:52
我在网上搜到了有两种方法,
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,那怎么用呢? 能不能具体点。俯身倾耳以请
...全文
1043 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
抢不到就去偷 2015-12-25
  • 打赏
  • 举报
回复
引用 5 楼 bzcode 的回复:
文字识别只能ocr,有收费的有免费的。office中的outlook自带ocr,可以用来调用。
是在添加引用的com里找么? 不太会弄,麻烦具体点
抢不到就去偷 2015-12-25
  • 打赏
  • 举报
回复
引用 6 楼 caozhy 的回复:
用office自带的ocr,效率高
是在添加引用的com中找么?不太会弄,能不能具体点
抢不到就去偷 2015-12-24
  • 打赏
  • 举报
回复
自顶!自顶!自顶!
threenewbee 2015-12-24
  • 打赏
  • 举报
回复
用office自带的ocr,效率高
bzcode 2015-12-24
  • 打赏
  • 举报
回复
文字识别只能ocr,有收费的有免费的。office中的outlook自带ocr,可以用来调用。
john_QQ:2335298917 2015-12-24
  • 打赏
  • 举报
回复
用OCR,图片上的文字需要先识别成字符串才行
angel6709 2015-12-24
  • 打赏
  • 举报
回复
ocr 1
lvfeng_95 2015-12-24
  • 打赏
  • 举报
回复
可以学习下ocr

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧