Page 1 of 1

Acquire image from TWAIN device and read barcodes

Posted: Tue May 05, 2009 2:14 pm
by Loïc
Note: This sample demonstrate a way to use the barcode detection capability of a TWAIN scanner. To work, your scanner must implement a built-in barcode recognition engine.

To your scanner doesn't have barcode engine, we suggest to use our GdPicture 1D Barcode Recognition Plugin: https://www.gdpicture.com/products/plugi ... nition.php


Code: Select all

   Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command4.Click
        Dim ImageID As Integer
        Dim oGdPictureImaging As New GdPicture.GdPictureImaging

        oGdPictureImaging.SetLicenseNumber("XXX") 'Replace XXX by a valid demo or commercial license KEY
        If oGdPictureImaging.TwainOpenDefaultSource(Me.Handle) Then
            If oGdPictureImaging.TwainIsBarcodeDetectionAvailable Then
                oGdPictureImaging.TwainSetBarcodeDetection(True)
                ImageID = oGdPictureImaging.TwainAcquireToGdPictureImage(Me.Handle)
                If ImageID <> 0 Then
                    Dim BarCodeCount As Integer = oGdPictureImaging.TwainBarCodeGetCount

                    MsgBox(Str(BarCodeCount) + " barcode have been found in the scanned image")

                    For i As Integer = 1 To BarCodeCount
                        MsgBox("Type of barcode " + Str(i) + " is: " + oGdPictureImaging.TwainBarCodeGetType(i).ToString)
                        MsgBox("Value of barcode " + Str(i) + " is: " + oGdPictureImaging.TwainBarCodeGetValue(i))
                    Next

                    Call oGdPictureImaging.ReleaseGdPictureImage(ImageID)
                End If
            Else
                MsgBox("Error: Barcode detection is not available on this scanner")
            End If

            Call oGdPictureImaging.TwainCloseSource()
            MsgBox("Done !")
        Else
            MsgBox("can't open default source, twain state is: " & oGdPictureImaging.TwainGetState.ToString)
        End If
    End Sub

Re: Acquire image from TWAIN device and read barcodes

Posted: Fri Mar 29, 2019 10:29 pm
by Gabriela