Provides access to the language environment of the character sets used by the
IOcrEngine.
Syntax
Visual Basic (Declaration) | |
---|
Public Interface IOcrLanguageManager |
C# | |
---|
public interface IOcrLanguageManager |
C++/CLI | |
---|
public interface class IOcrLanguageManager |
Example
This example will enumerate the languages supported by the OCR engine then enable the current culture language plus German.
Visual Basic | Copy Code |
---|
Public Sub OcrLanguageManagerExample()
RasterSupport.Unlock(RasterSupportType.Document, "Replace with your own key here")
RasterSupport.Unlock(RasterSupportType.OcrPlus, "Replace with your own key here")
RasterSupport.Unlock(RasterSupportType.OcrPlusPdfLeadOutput, "Replace with your own key here")
Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, False)
ocrEngine.Startup(Nothing, Nothing, Nothing, Nothing)
Dim supportedLanguages() As String = ocrEngine.LanguageManager.GetSupportedLanguages()
Console.WriteLine("Supported languages:")
For Each supportedLanguage As String In supportedLanguages
Dim ci As New CultureInfo(supportedLanguage)
Console.WriteLine(" {0} ({1})", supportedLanguage, ci.EnglishName)
Next
Dim currentCulture As CultureInfo = CultureInfo.CurrentCulture
Dim name As String = currentCulture.TwoLetterISOLanguageName
Dim supported As Boolean = ocrEngine.LanguageManager.IsLanguageSupported(name)
If (Not supported) Then
name = currentCulture.Name
supported = ocrEngine.LanguageManager.IsLanguageSupported(name)
End If
If (supported) Then
Console.WriteLine("Current culture is {0}, and it is supported by this OCR engine. Enabling only this language and German now", currentCulture.EnglishName)
ocrEngine.LanguageManager.EnableLanguages(New String() {name, "de"})
If Not ocrEngine.LanguageManager.SupportsEnablingMultipleLanguages Then
Console.WriteLine("This engine supports enabling only one language at a time, so only the first language we enabled will be used")
End If
Dim enabledLanguages() As String = ocrEngine.LanguageManager.GetEnabledLanguages()
Console.WriteLine("Current enabled languages in the engine are:")
For Each enabledLanguage As String In enabledLanguages
Dim ci As New CultureInfo(enabledLanguage)
Console.WriteLine(" {0} ({1})", enabledLanguage, ci.EnglishName)
Next
Else
Console.WriteLine("Current culture is {0}, and it is not supported by this OCR engine", currentCulture.EnglishName)
End If
ocrEngine.Shutdown()
End Using
End Sub |
C# | Copy Code |
---|
public void OcrLanguageManagerExample() { // Unlock the support needed for LEADTOOLS Plus OCR engine RasterSupport.Unlock(RasterSupportType.Document, "Replace with your own key here"); RasterSupport.Unlock(RasterSupportType.OcrPlus, "Replace with your own key here"); RasterSupport.Unlock(RasterSupportType.OcrPlusPdfLeadOutput, "Replace with your own key here"); // Create an instance of the engine using(IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false)) { // Start the engine using default parameters ocrEngine.Startup(null, null, null, null); // Show languages supported by this engine string[] supportedLanguages = ocrEngine.LanguageManager.GetSupportedLanguages(); Console.WriteLine("Supported languages:"); foreach(string supportedLanguage in supportedLanguages) { // Get the friendly name of this language using the .NET CultureInfo class CultureInfo ci = new CultureInfo(supportedLanguage); Console.WriteLine(" {0} ({1})", supportedLanguage, ci.EnglishName); } // Check if current culture info language is supported CultureInfo currentCulture = CultureInfo.CurrentCulture; string name = currentCulture.TwoLetterISOLanguageName; bool supported = ocrEngine.LanguageManager.IsLanguageSupported(name); if(!supported) { name = currentCulture.Name; supported = ocrEngine.LanguageManager.IsLanguageSupported(name); } if(supported) { Console.WriteLine("Current culture is {0}, and it is supported by this OCR engine. Enabling only this language and German now", currentCulture.EnglishName); ocrEngine.LanguageManager.EnableLanguages(new string[] { name, "de" }); // If this engine does not support enabling multiple languages (currently the LEADTOOLS Advantage OCR engine), then GetEnabledLanguages // will always return an array of 1, make a note of this if(!ocrEngine.LanguageManager.SupportsEnablingMultipleLanguages) Console.WriteLine("This engine supports enabling only one language at a time, so only the first language we enabled will be used"); string[] enabledLanguages = ocrEngine.LanguageManager.GetEnabledLanguages(); Console.WriteLine("Current enabled languages in the engine are:"); foreach(string enabledLanguage in enabledLanguages) { // Get the friendly name of this language using the .NET CultureInfo class CultureInfo ci = new CultureInfo(enabledLanguage); Console.WriteLine(" {0} ({1})", enabledLanguage, ci.EnglishName); } } else Console.WriteLine("Current culture is {0}, and it is not supported by this OCR engine", currentCulture.EnglishName); ocrEngine.Shutdown(); } } |
Remarks
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also