Page 1 of 1

Select Barcode

Posted: Tue Mar 02, 2010 10:27 pm
by igorot
I'm trying to use Barcode.NET with the Twain.NET and wondering if it's possible to manually select a barcode image within a page. In instances that there are more than 1 barcode in a page, I'd want a user to be able to pick the barcode to use for indexing. If so, how? Thanks..

Re: Select Barcode

Posted: Wed Mar 03, 2010 9:39 am
by Alex
Hello,

You can acquire images from scanner using VintaSoftTwain.NET Library and search barcodes in acquired images using VintaSoftBarcode.NET Library.

Here is a snippet of code:

Code: Select all

' Create a BarcodeReader object
Dim barcodeReader As BarcodeReader = New BarcodeReader()

' Extract only Code 128 barcodes
barcodeReader.Settings.ScanBarcodeTypes = BarcodeType.Code128
' Extract onnly horizontal barcodes
barcodeReader.Settings.ScanDirection = ScanDirection.LeftToRight Or ScanDirection.RightToLeft
' Analyze every 5 row and column
barcodeReader.Settings.ScanInterval = 5
' Extract 10 first barcodes
barcodeReader.Settings.MaxBarcodes = 10

' Manual mode of threshold detection
barcodeReader.Settings.ThresholdMode = ThresholdMode.Manual
' Number of steps between minimal and maximal threshold values
barcodeReader.Settings.ThresholdIterations = 15
' Minimal threshold value
barcodeReader.Settings.Threshold1D = 480
' Maximal threshold value
barcodeReader.Settings.Threshold2D = 550

' Acquire images from scanner and search barcodes in acquired images
Try
   ' Open the scanning library
   VSTwain1.StartDevice()

   ' Select a scanner
   VSTwain1.SelectSource()
   ' Disable UI
   VSTwain1.ShowUI = false

   ' Acquire images
   While VSTwain1.AcquireModal()
       ' Extract barcodes
       Dim Infos() As IBarcodeInfo = barcodeReader.ReadBarcodes(VSTwain1.GetCurrentImage())

      ' If barcodes are detected
       Dim resultString As String
       If Infos IsNot Nothing Or Infos.Length > 1 Then
           ' Get information about extracted barcodes
           resultString = "Codes detected" + Infos.Length.ToString() + "]:" + Environment.NewLine
           Dim i As Integer
           For i = 0 To Infos.Length - 1
               resultString += Infos(i).ToString() + Environment.NewLine
           Next i
       End If
   End While

   ' Close the scanning library
   VSTwain1.StopDevice()
   MsgBox "Scan completed."
Catch ex As TwainException
   MsgBox(ex.Message)
End Try
Best regards, Alexander