Class OneOcrService
OneOCR engine implementation of IOCRService using P/Invoke
into the native oneocr.dll (Windows 11 SnippingTool OCR engine).
No WinRT, no Windows App SDK, no package identity required.
Pass engine settings directly to CreateSessionAsync(IReadOnlyDictionary<string, object>, CancellationToken).
Inherited Members
Namespace: Zaya.OCR.Impl.OneOcr
Assembly: Zaya.OCR.Impl.OneOcr.dll
Syntax
public sealed class OneOcrService : IOCRService, IDisposable
Remarks
EngineId is oneocr.
Settings are exposed via Settings as SettingDescriptor instances
for UI hosts, and accepted as a string-keyed dictionary by
CreateSessionAsync(IReadOnlyDictionary<string, object>, CancellationToken).
Use OneOcrConfig for a typed alternative.
Setting keys
| Key | Type | Default | Description |
|---|---|---|---|
source | enum string | auto |
Where to load engine files from.
Values: auto (SnippingTool, then URL fallback),
snippingtool, directory, url.
|
directoryPath | directory path | (none) |
Local folder with oneocr.dll, onnxruntime.dll, and oneocr.onemodel.
Required when source is directory.
|
downloadUrl | URL | GitHub Zaya.External OneOCR.zip release |
Package URL used when source is url,
and as fallback when source is auto.
|
cacheDirectory | directory path | %TEMP%\Zaya\OneOcr |
Writable cache for copied/extracted engine files
(auto, snippingtool, url).
Hosts such as ScreenTranslator may override this key.
|
minConfidence | integer 0–100 | 70 | Minimum word confidence (percent). Words below the threshold are dropped. |
Example:
using var ocr = new OneOcrService();
using var session = await ocr.CreateSessionAsync(new Dictionary<string, object>
{
["source"] = "auto",
["minConfidence"] = 50,
});
var result = await session.RecognizeAsync(image);
Constructors
| Edit this page View SourceOneOcrService()
Initializes a new instance using Zaya.Logging.Services.EmptyLoggingWrapper.Instance.
Declaration
public OneOcrService()
OneOcrService(ILoggingWrapper)
Initializes a new instance with the specified logging wrapper.
Declaration
public OneOcrService(ILoggingWrapper loggingWrapper)
Parameters
| Type | Name | Description |
|---|---|---|
| ILoggingWrapper | loggingWrapper | Logging wrapper used when creating sessions. |
Properties
| Edit this page View SourceDescription
Gets the UI description for this engine (localized).
Declaration
public LocalizedString Description { get; }
Property Value
| Type | Description |
|---|---|
| LocalizedString |
DisplayName
Gets the UI display name for this engine (localized).
Declaration
public LocalizedString DisplayName { get; }
Property Value
| Type | Description |
|---|---|
| LocalizedString |
EngineId
Gets a unique identifier for this OCR engine (e.g., "oneocr", "tesseract"). Used for profile serialization and engine lookup.
Declaration
public string EngineId { get; }
Property Value
| Type | Description |
|---|---|
| string |
IsAvailable
Gets whether this OCR engine is available on the current system.
Declaration
public bool IsAvailable { get; }
Property Value
| Type | Description |
|---|---|
| bool |
PreferredPixelFormat
Gets the pixel format preferred by this OCR engine. The caller (e.g., a screenshot module) can use this to deliver pixels in the optimal format without extra conversion.
Declaration
public PixelFormat PreferredPixelFormat { get; }
Property Value
| Type | Description |
|---|---|
| PixelFormat |
Settings
Gets the engine-specific settings declared by OneOCR
(source, directoryPath, downloadUrl, cacheDirectory, minConfidence).
Declaration
public IReadOnlyList<SettingDescriptor> Settings { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<SettingDescriptor> |
Remarks
See the type-level remarks on OneOcrService for key names, defaults, and visibility rules.
Methods
| Edit this page View SourceCreateSessionAsync(IReadOnlyDictionary<string, object>, CancellationToken)
Creates a new OCR session with the specified engine settings.
Declaration
public Task<IOCRSession> CreateSessionAsync(IReadOnlyDictionary<string, object> settings, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyDictionary<string, object> | settings | Dictionary of setting keys (see type-level remarks). Missing keys use descriptor defaults. |
| CancellationToken | cancellationToken | Token to cancel session creation (e.g. while downloading). |
Returns
| Type | Description |
|---|---|
| Task<IOCRSession> | An active OCR session ready to recognize text. |
CreateSessionAsync(CancellationToken)
Creates a new OCR session with the default engine settings.
Declaration
public Task<IOCRSession> CreateSessionAsync(CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | Token to cancel session creation. |
Returns
| Type | Description |
|---|---|
| Task<IOCRSession> | An active OCR session ready to recognize text. |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()