我正在使用此代码:
IronTesseract tes=new IronTesseract(){Language=OcrLanguage.English};
OcrInput input=new OcrInput();
input.LoadImage(AnyBitmap.FromBitmap(CaptureScrcpy()));
return tes.Read(input);
我在第三行得到
InvalidCastException: Object must implement IConvertible
。我的项目位于 net 4.8 上,如果错误是因为我的系统程序集未更新,因此它们没有实现 IConvertible,我不知道如何解决该问题。 private Bitmap CaptureScrcpy () {
Native.RECT rc=GetScrcpyRect();
Bitmap b=new Bitmap(+(rc.right-rc.left)*2,+(rc.bottom-rc.top)*2,PixelFormat.Format32bppArgb);
using (Graphics gfx=Graphics.FromImage(b))
Native.Native32.PrintWindow(this.scrcpy.MainWindowHandle,gfx.GetHdc(),Native.PW_CLIENTONLY);
return b;
}
即使irocr说AnyBitmap和其他类型(包括System.Drawing.Bitmap)之间存在显式转换,
(AnyBitmap)(CaptureScrcpy())
由于无效转换而无法编译。我应该怎么办?我不想保存文件然后用 Ironocr 读取它,因为这是多余的
我只是像这样“修复”它
OcrInput input=new OcrInput();
using (MemoryStream stream=new MemoryStream())
{
CaptureScrcpy().Save(stream,ImageFormat.Bmp);
input.LoadImage(AnyBitmap.FromBytes(stream.ToArray()));
}
//input.LoadImage(AnyBitmap.FromBitmap(CaptureScrcpy()));
return tes.Read(input);
但我仍然会等着看是否有人可以回答,这样我就可以使用非黑客方法?