using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
[Nullable(0), NullableContext(1)]
internal class Program
{
[NullableContext(0)]
public delegate void SetResultDelegate(IntPtr result);
[Nullable(0)]
public class StringResult
{
public string result_ = "";
public void SetResult(IntPtr dt)
{
int num = 0;
while (Marshal.ReadByte(dt, num) != 0)
{
num++;
}
byte[] array = new byte[num];
Marshal.Copy(dt, array, 0, num);
this.result_ = Encoding.get_UTF8().GetString(array);
}
public string GetResult()
{
return this.result_;
}
}
[DllImport("wcocr.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern bool wechat_ocr([MarshalAs(21)] string ocr_exe, [MarshalAs(21)] string wechat_dir, [MarshalAs(20)] string imgfn, Program.SetResultDelegate set_res);
[DllImport("wcocr.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void stop_ocr();
private static void Main(string[] args)
{
if (args.Length != 3)
{
Console.WriteLine("Usage: wcocr.exe ocr_exe wechat_dir imgfn");
return;
}
Program.StringResult stringResult = new Program.StringResult();
Program.SetResultDelegate set_res = new Program.SetResultDelegate(stringResult.SetResult);
bool flag = Program.wechat_ocr(args[0], args[1], args[2], set_res);
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(18, 2);
defaultInterpolatedStringHandler.AppendLiteral("OCR Success: ");
defaultInterpolatedStringHandler.AppendFormatted<bool>(flag);
defaultInterpolatedStringHandler.AppendLiteral(" res:");
defaultInterpolatedStringHandler.AppendFormatted(stringResult.GetResult());
Console.WriteLine(defaultInterpolatedStringHandler.ToStringAndClear());
Program.stop_ocr();
}
}
原文
GitHub - swigger/wechat-ocr
整理资料
https://download.youkuaiyun.com/download/qq_36664772/90776859
如有侵权联系删除 , C# Net WeChatOCR.rar c# 调用微信ocr 识别 调用方式 cmd:ConsoleApp2.exe test.png
注意:进过测试,win7电脑正常用 w10部分电脑会卡死 部分win10能正常用
用之前要测试是否断网可用

被折叠的 条评论
为什么被折叠?



