ITLDG.WeChatOcr
1.0.0
dotnet add package ITLDG.WeChatOcr --version 1.0.0
NuGet\Install-Package ITLDG.WeChatOcr -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ITLDG.WeChatOcr" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ITLDG.WeChatOcr" Version="1.0.0" />
<PackageReference Include="ITLDG.WeChatOcr" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ITLDG.WeChatOcr --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ITLDG.WeChatOcr, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ITLDG.WeChatOcr@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ITLDG.WeChatOcr&version=1.0.0
#tool nuget:?package=ITLDG.WeChatOcr&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
WeChatOcr
基于 wechat-ocr 的 .NET Framework 库,用于调用微信侧的 WeChatOCR 组件执行图片文字识别,并将识别结果反序列化为结构化对象。
功能
- 在常见安装路径与注册表中查找微信安装目录。
- 在
%APPDATA%下查找并使用wxocr.dll或WeChatOCR.exe。 - 如用户未安装微信或缺少 OCR 组件,尝试从程序集嵌入资源写出所需的本地文件。
- 通过 P/Invoke 调用本地桥接库
wcocr.dll进行 OCR,使用回调获取字符串结果并解析为OcrResult。
主要类型
WeChatOcr:核心类,包含查找、写出资源与调用 OCR 的方法。Ocr(string picPath):自动查找 OCR 可执行与微信目录并识别图片,返回OcrResult。Ocr(string ocrExe, string wechatDir, string imgPath):指定 OCR 可执行文件与微信目录进行识别。CallWechatOcr(...):直接调用本地桥接库并返回原始 JSON 字符串。StopOcr():停止当前 OCR 会话(注意连续识别时不要调用)。
OcrResult/OcrResponse:用于承载反序列化后的 OCR 结果数据(错误码、图片信息、识别区域及文本等)。
使用示例
//直接使用默认查找逻辑
OcrResult res = WeChatOcr.Ocr(@"C:\path\to\image.png");
if (res != null && res.ErrCode ==0)
{
foreach (var r in res.OcrResponse)
Console.WriteLine(r.Text);
}
// 指定 OCR 可执行文件与微信目录
OcrResult res2 = WeChatOcr.Ocr(@"C:\WeChatOCR\WeChatOCR.exe", @"C:\Program Files\Tencent\WeChat", @"C:\img.png");
安全与许可
- 本项目依赖的原生组件可能来自第三方或微信客户端,请在生产环境使用前核查来源与许可。
限制与注意事项
- 运行时会尝试写出原生 DLL/EXE 到运行目录,需保证应用有写权限。
打包与发布
编译Release版本后,可使用以下命令生成 NuGet 包:
nuget pack WeChatOcr.nuspec
贡献
如需改进或修复,请在仓库中创建 issue 或提交 pull request,并提供可重现步骤与运行环境信息(Windows 版本、微信版本)。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net48 is compatible. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.8
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 142 | 11/8/2025 |
支持本地微信和内嵌文件两种方式,无外部依赖。