GdPicture.NET.14.API
GdPicture14 Namespace / GdPictureOCR Class / SetImage Method
A unique image identifier of the created image object. You can take advantages of the GdPictureImaging class and its methods to obtain this identifier.
Example





In This Topic
SetImage Method (GdPictureOCR)
In This Topic
Sets up the specified image object, so that it is subsequently used when you start the next OCR process. This step is mandatory before running any OCR.

This aproach permits you to highly improve performance when running multiple subsequent OCR processes on the same image, for example using different regions of interest or using different charsets, etc.

Syntax
'Declaration
 
Public Function SetImage( _
   ByVal ImageID As Integer _
) As GdPictureStatus
public GdPictureStatus SetImage( 
   int ImageID
)
public function SetImage( 
    ImageID: Integer
): GdPictureStatus; 
public function SetImage( 
   ImageID : int
) : GdPictureStatus;
public: GdPictureStatus SetImage( 
   int ImageID
) 
public:
GdPictureStatus SetImage( 
   int ImageID
) 

Parameters

ImageID
A unique image identifier of the created image object. You can take advantages of the GdPictureImaging class and its methods to obtain this identifier.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK

We strongly recommend always checking this status first.

Remarks
Please note that setting up an image is a mandatory step before running any OCR process. This approach allows you to take all benefits of the speed optimization when performing OCR.
Example
How to set the image you want to process and how to subsequently run the OCR on this image.
Dim caption As String = "Example: SetImage"
Using gdpictureOCR As GdPictureOCR = New GdPictureOCR()
    'Set up your prefered parameters for OCR.
    gdpictureOCR.ResourcesFolder = "\GdPicture.Net 14\redist\OCR"
    If gdpictureOCR.AddLanguage(OCRLanguage.English) = GdPictureStatus.OK Then
        'Set up the image you want to process.
        Dim gdpictureImaging As GdPictureImaging = New GdPictureImaging()
        'Display the standard open file dialog to allow you to select the file.
        Dim image As Integer = gdpictureImaging.CreateGdPictureImageFromFile("")
        If (gdpictureImaging.GetStat() = GdPictureStatus.OK) AndAlso
           (gdpictureOCR.SetImage(image) = GdPictureStatus.OK) Then
            'Run the OCR process.
            Dim result As String = gdpictureOCR.RunOCR()
            If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
                'Save the result.
                If gdpictureOCR.SaveAsText(result, "my_first_OCR_result.txt", OCROutputTextFormat.Utf16, True) = GdPictureStatus.OK Then
                    MessageBox.Show("The OCR result has been successfully saved.", caption)
                Else
                    MessageBox.Show("The SaveAsText() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
                End If
            Else
                MessageBox.Show("The OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
            End If
            'Release the used image.
            gdpictureImaging.ReleaseGdPictureImage(image)
        Else
            MessageBox.Show("The error occurred when setting up the image: " + gdpictureImaging.GetStat().ToString() + " or " + gdpictureOCR.GetStat().ToString(), caption)
        End If
        gdpictureImaging.Dispose()
    Else
        MessageBox.Show("The AddLanguage() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
    End If
    gdpictureOCR.ReleaseOCRResults()
End Using
string caption = "Example: SetImage";
using (GdPictureOCR gdpictureOCR = new GdPictureOCR())
{
    //Set up your prefered parameters for OCR.
    gdpictureOCR.ResourcesFolder = "\\GdPicture.Net 14\\redist\\OCR";
    if (gdpictureOCR.AddLanguage(OCRLanguage.English) == GdPictureStatus.OK)
    {
        //Set up the image you want to process.
        GdPictureImaging gdpictureImaging = new GdPictureImaging();
        //The standard open file dialog displays to allow you to select the file.
        int image = gdpictureImaging.CreateGdPictureImageFromFile("");
        if ((gdpictureImaging.GetStat() == GdPictureStatus.OK) &&
            (gdpictureOCR.SetImage(image) == GdPictureStatus.OK))
        {
            //Run the OCR process.
            string result = gdpictureOCR.RunOCR();
            if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
            {
                //Save the result.
                if (gdpictureOCR.SaveAsText(result, "my_first_OCR_result.txt", OCROutputTextFormat.Utf16, true) == GdPictureStatus.OK)
                    MessageBox.Show("The OCR result has been successfully saved.", caption);
                else
                    MessageBox.Show("The SaveAsText() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
            }
            else
            {
                MessageBox.Show("The OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
            }
            //Release the used image.
            gdpictureImaging.ReleaseGdPictureImage(image);
        }
        else
            MessageBox.Show("The error occurred when setting up the image: " + gdpictureImaging.GetStat().ToString() + " or " + gdpictureOCR.GetStat().ToString(), caption);
        gdpictureImaging.Dispose();
    }
    else
        MessageBox.Show("The AddLanguage() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
    gdpictureOCR.ReleaseOCRResults();
}
See Also