In This Topic
Programming / Barcode Reading & Writing / Recognizing 1D barcodes using GdPicture

Recognizing 1D barcodes using GdPicture

In This Topic

Recognizing barcodes using GdPicture is an easy task to accomplish. Here we will show you in simple steps, how to go about achieving that.

Copy Code
'We assume that GdPicture has been correctly installed and unlocked.
Dim oGdPictureImaging As New GdPictureImaging()
Dim imageId As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("input.jpg")
If oGdPictureImaging.GetStat() <> GdPictureStatus.OK Then
    MessageBox.Show("The image can't be loaded! Error: " + oGdPictureImaging.GetStat().ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
    'Specifying 1D barcode search types to be Code39 and Code128.
    Dim barcodeType As Barcode1DReaderType = Barcode1DReaderType.Barcode1DReaderCode39 Or Barcode1DReaderType.Barcode1DReaderCode128
    'Starting the barcode scanning process.
    If oGdPictureImaging.Barcode1DReaderDoScan(imageId, Barcode1DReaderScanMode.BestQuality, barcodeType, False, 1) = GdPictureStatus.OK Then
        'Obtaining the number of barcodes found.
        Dim barcodeCount As Integer = oGdPictureImaging.Barcode1DReaderGetBarcodeCount()
        'If barcodes has been found:
        If barcodeCount > 0 Then
            Dim message As String = "Number of barcodes: " + barcodeCount.ToString()
            'For each barcode display the number, the value and the angle it is drawn at.
            For i As Integer = 1 To barcodeCount
                message = message + vbCrLf + "Barcode No: " + i.ToString() +
                                "    Value: " + oGdPictureImaging.Barcode1DReaderGetBarcodeValue(i).ToString() +
                                "    Angle: " + oGdPictureImaging.Barcode1DReaderGetBarcodeSkewAngle(i).ToString()
                Next
                MessageBox.Show(message, "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageBox.Show("No barcode detected !", "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
        'Releasing detection info from memory.
        oGdPictureImaging.Barcode1DReaderClear()
    End If
    'Releasing the image.
    oGdPictureImaging.ReleaseGdPictureImage(imageId)
End If
oGdPictureImaging.Dispose()
Copy Code
//We assume that GdPicture has been correctly installed and unlocked.
GdPictureImaging oGdPictureImaging = new GdPictureImaging();
int imageId = oGdPictureImaging.CreateGdPictureImageFromFile("input.jpg");
if (oGdPictureImaging.GetStat() != GdPictureStatus.OK)
{
    MessageBox.Show("The image can't be loaded! Error: " + oGdPictureImaging.GetStat().ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
    //Specifying 1D barcode search types to be Code39 and Code128.
    Barcode1DReaderType barcodeType = Barcode1DReaderType.Barcode1DReaderCode39 | Barcode1DReaderType.Barcode1DReaderCode128;
    //Starting the barcode scanning process.
    if (oGdPictureImaging.Barcode1DReaderDoScan(imageId, Barcode1DReaderScanMode.BestQuality, barcodeType, false, 1) == GdPictureStatus.OK)
    {
        //Obtaining the number of barcodes found.
        int barcodeCount = oGdPictureImaging.Barcode1DReaderGetBarcodeCount();
        //If barcodes has been found:
        if (barcodeCount > 0)
        {
            string message = "Number of barcodes: " + barcodeCount.ToString();
            //For each barcode display the number, the value and the angle it is drawn at.
            for (int i = 1; i <= barcodeCount; i++)
            {
                message = message + "\nBarcode No: " + i.ToString() +
                            "    Value: " + oGdPictureImaging.Barcode1DReaderGetBarcodeValue(i).ToString() +
                            "    Angle: " + oGdPictureImaging.Barcode1DReaderGetBarcodeSkewAngle(i).ToString();
            }
            MessageBox.Show(message, "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        else
        {
            MessageBox.Show("No barcode detected !", "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //Release detection info from memory.
        oGdPictureImaging.Barcode1DReaderClear();
    }
    //Release the image.
    oGdPictureImaging.ReleaseGdPictureImage(imageId);
}
oGdPictureImaging.Dispose();

Do not forget to release the barcode reader and the image resource once you are done, like it is shown above.