Reference Guide
Programming / Document Cleanup / Auto-inverting negative documents
In This Topic
    Auto-inverting negative documents
    In This Topic

    Negative documents are documents, that have a reverse color photometry: text is white and the background is black. Since intelligent document recognition assumes the opposite, you need to invert the images. But what if you have hundreds or thousands of them? You cannot possibly invert them manually one by one.

    Here is an example how to invert negative documents.

    Copy Code
    'We assume that GdPicture has been correctly installed and unlocked.
    Dim oGdPictureImaging As New GdPictureImaging()
    'Loading the image from a file.
    Dim imageId As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("Image.tif")
    'Checking if the image resource has been loaded correctly.
    If oGdPictureImaging.GetStat() <> GdPictureStatus.OK Then
        MessageBox.Show("The image can't be loaded. Error: " + oGdPictureImaging.GetStat().ToString(), "Auto-invertion Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Else
        'Checking if the image is inverted.
        Dim isNegative As Boolean = oGdPictureImaging.IsNegative(imageId)
        'If the image is inverted, invert it back.
        If isNegative Then
            Dim status As GdPictureStatus = oGdPictureImaging.FxNegative(imageId)
            If status = GdPictureStatus.OK Then
                'Here you can process your image...
                MessageBox.Show("Done!", "Auto-invertion Example", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show("Error: " + status.ToString(), "Auto-invertion Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        End If
        'Releasing the image resource.
        oGdPictureImaging.ReleaseGdPictureImage(imageId)
    End If
    oGdPictureImaging.Dispose()
    Copy Code
    //We assume that GdPicture has been correctly installed and unlocked.
    GdPictureImaging oGdPictureImaging = new GdPictureImaging();
    //Loading the image from a file.
    int imageId = oGdPictureImaging.CreateGdPictureImageFromFile("Image.tif");
    //Checking if the image resource has been loaded correctly.
    if (oGdPictureImaging.GetStat() != GdPictureStatus.OK)
    {
        MessageBox.Show("The image can't be loaded. Error: " + oGdPictureImaging.GetStat().ToString(), "Auto-invertion Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    else
    {
        //Checking if the image is inverted.
        bool isNegative = oGdPictureImaging.IsNegative(imageId);
        //If the image is inverted, invert it back.
        if (isNegative)
        {
            GdPictureStatus status = oGdPictureImaging.FxNegative(imageId);
            if (status == GdPictureStatus.OK)
                //Here you can process your image...
                MessageBox.Show("Done!", "Auto-invertion Example", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
                MessageBox.Show("Error: " + status.ToString(), "Auto-invertion Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        //Releasing the image resource.
        oGdPictureImaging.ReleaseGdPictureImage(imageId);
    }
    oGdPictureImaging.Dispose();