To read barcodes
Create BarcodeReader object
Configure direction of barcodes (default horizontal, vertical and diagonal)
Activate the required barcode type(s). Setting Auto1D to 'true' reads the most common 1D barcodes.
To read the barcode values directly
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);
}
}