ClearImageNet Send comments on this topic.
Reading Barcodes

To read barcodes

  1. Create BarcodeReader object

  2. Configure direction of barcodes (default horizontal, vertical and diagonal)

  3. Activate the required barcode type(s).   Setting Auto1D to 'true' reads the most common 1D barcodes.

  4. To read the barcode values directly

    • Call one of the Read methods

    • Iterate through the returned Barcode [] array

  5. OR To read barcode values in event handler

    • Configure reader event handler to obtain the barcode each time that it is found

    • Call one of the Read methods

    • Process barcodes in event handler on BarcodeFound event

 

Example:  Reading PDF417 barcodes

 

private void ReadPdf417 (string filename, int page)

{

try

{

BarcodeReader reader = new BarcodeReader();

// for faster reading specify only required direction

reader.Horizontal = true; reader.Vertical = true; reader.Diagonal = true;

// specify type

reader.Pdf417 = true;

// read barcodes

Barcode[] barcodes = reader.Read (filename, page);

// process results

foreach (Barcode bc in barcodes)

{ProcessBarcode (bc);}

}

catch(Exception ex)

{

ProcessError (ex);

}

}

 

 

Example:  Reading 1D barcodes using event handler

 

// Event Handler

private void _OnBarcodeFound (object sender, BarcodeFoundEventArgs e)

{
ProcessBarcode (
e.Barcode);

// e.cancel = (e.Count == 3); // Cancel after 3 barcodes are found

}

 

private void ReadBarcodesWithEvents (string filename, int page)

{

try

{

BarcodeReader reader = new BarcodeReader();

// configure directions

reader.Horizontal = true; reader.Vertical = false; reader.Diagonal = false;

//configure types.  Select specific types for faster processing

reader.Auto1D = true;

// configure event handler

reader.BarcodeFoundEvent +=

new BarcodeReader.BarcodeFoundEventHandler(_OnBarcodeFound);

// read barcodes

reader.Read (filename, page);

}

catch(Exception ex)

{

ProcessError (ex);

}

}