ImageGear .NET v25.0 - Updated
Load and Import Images
User Guide > How to Work with... > OCR > How to... > Load and Import Images

The Recognition engine uses its own internal image storage. To supply recognition engine with input data, you should first load an image to ImageGear storage (ImGearPage). You can load images from any ImageGear supported image location, such as file, URL, or memory, or retrieve images from a scanner. Then you can import the image into Recognition image storage (ImGearOCRPage Class). Use the ImGearOCR.ImportPage Method for this.

If the source ImGearPage contains a grayscale image, the import method can convert the imported image to a bitonal one. If the source ImGearPage contains a color image, the import method can convert the imported image to grayscale or bitonal. The way this method will handle the different image types (such as bitonal, grayscale, or color images) is called the primary color reduction mode.

This code demonstrates loading and recognizing the TEST1.TIF image file. The image contains English, machine-printed text. The result will be saved in the TEST1.TXT text file.

C#
Copy Code
using System.IO;
using ImageGear.Core;
using ImageGear.Formats;
using ImageGear.OCR;
public void RecognizeFile(string fileToBeRecognizedPath, string outputfilePath)
{
    ImGearPage igPage;
    using (FileStream localFile = new FileStream(fileToBeRecognizedPath, FileMode.Open, FileAccess.Read))
        igPage = ImGearFileFormats.LoadPage(localFile, 0);
 
    using (ImGearOCR igOcr = ImGearOCR.Create())
    using (ImGearOCRPage igOcrPage = igOcr.ImportPage(igPage as ImGearRasterPage))
    {
        igOcrPage.Recognize();
        File.WriteAllText(outputfilePath, igOcrPage.Text);
    }
}
VB.NET
Copy Code
Imports System.IO
Imports ImageGear.Core
Imports ImageGear.Formats
Imports ImageGear.OCR
Public Sub RecognizeFile(fileToBeRecognizedPath As String, outputfilePath As String)
    Dim igPage As ImGearPage
    Using localFile As New FileStream(fileToBeRecognizedPath, FileMode.Open, FileAccess.Read)
        igPage = ImGearFileFormats.LoadPage(localFile, 0)
    End Using
 
    Using igOcr As ImGearOCR = ImGearOCR.Create(), _
        igOcrPage As ImGearOCRPage = igOcr.ImportPage(DirectCast(igPage, ImGearRasterPage))
        igOcrPage.Recognize()
        File.WriteAllText(outputfilePath, igOcrPage.Text)
    End Using
End Sub