Skip to content

ZGGSONG/WeChatOcr

Repository files navigation

Language

Description

Nuget

NuGet

Install-Package WeChatOcr

Usage

var weChatPath = @"D:\Apps\WeChat\[3.9.12.11]";	//Your WeChat installation directory
//1. image file
var imgPath = @"C:\Users\admin\Desktop\test.png";	//Your image file path
//2. image bytes
var imgBytes = new Byte[] {};	//Your image binary data
using var ocr = new ImageOcr(weChatPath);
ocr.Run(imgPath,	//imgPath or imgBytes
(path, result) =>
{
	try
	{
		if (result == null) return;
		var list = result?.OcrResult?.SingleResult;
		if (list == null)
		{
			//避免重复触发
			_tcs.SetResult("WeChatOCR get result is null");
			return;
		}

		var sb = new StringBuilder();
		for (var i = 0; i < list?.Count; i++)
		{
			if (list[i] is not { } item || string.IsNullOrEmpty(item.SingleStrUtf8))
				continue;

			sb.AppendLine(item.SingleStrUtf8);
		}

		_tcs.SetResult(sb.ToString());
	}
	catch (Exception ex)
	{
		System.Diagnostics.Debug.WriteLine(ex.Message);
	}
});

presentation

Study only, do not use for commercial purposes

Thanks