
正文
C#从Image上读取文本
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
今天通过C#来实现一个读取Image上文本的功能。
1. 环境准备:
1). 下载 Microsoft Office SharePoint Designer 2007.
2). 安装请参考KB:https://support.microsoft.com/kb/982760. 只需要安装Office Tools下Microsoft Office Document Imaging选项。
2. 在项目中引用Microsoft Office Document Imaging 12.0 Type Library,

关于具体读取的方法,请参考下面的代码:
private static string ExtractTextFromImage(string filePath)
{
Document modiDocument = new Document();
modiDocument.Create(filePath);
modiDocument.OCR(MiLANGUAGES.miLANG_ENGLISH,true,true);
MODI.Image modiImage = (modiDocument.Images[] as MODI.Image);
string extractedText = modiImage.Layout.Text;
modiDocument.Close();
return extractedText;
}
只需要传入图片地址,即可获得图片上的文本。
不过我也发现MODI有一些缺陷,一次只能读取一种语言。如果您要其他方式,欢迎在评论中指出。谢谢你的阅读。





