Provides easier access to Google ML Kit Text Recognition v2 API for .NET MAUI.
- Install the NuGet package
Install-Package MLKit.Maui.TextRecognition
- Initialize the Text Recognition Service in
MauiProgram.cs
.
var builder = MauiApp.CreateBuilder()
.UseMauiApp<App>()
builder.Services.AddTextRecognitionService();
- Use the service to get the OCR/Text results from a FileResult or image byte[]
private readonly ITextRecognitionService _textRecognitionService;
public TextRecognitionExampleViewModel(ITextRecognitionService textRecognitionService)
{
_textRecognitionService = textRecognitionService;
}
public async Task GetTextResults(FileResult imageFile)
{
TextRecognitionResult result = await _textRecognitionService.GetTextFromImage(imageFile);
}
public async Task GetTextResults(byte[] imageBytes)
{
TextRecognitionResult result = await _textRecognitionService.GetTextFromImage(imageBytes);
}