ClearImage 8 Help
How to read barcodes
Send Feedback

Glossary Item Box

The following examples demonstrate typical uses of BarcodeReader class 

Read specific barcode type Copy Code
// Configure barcode reader. Set direction and expected types
BarcodeReader reader = new BarcodeReader();
// Default for all directions is 'true'
reader.Horizontal = true; reader.Vertical = false; reader.Diagonal = false;
reader.Code39 = true;
// Read and process barcodes
Barcode[] barcodes = reader.Read(fileName, pageNumber);
foreach (Barcode bc in barcodes)
  { Console.WriteLine(bc.Text);} 

 

Automatically detect 1D barcode type Copy Code
// Configure barcode reader
BarcodeReader reader = new BarcodeReader();
reader.Auto1D = true; // <=== ENABLE AUTOMATIC BARCODE DETECTION
// Read and process barcodes
Barcode[] barcodes = reader.Read(fileName, pageNumber);
foreach (Barcode bc in barcodes)
  { Console.WriteLine (bc.Text); }

 

Read 2D barcode Copy Code
// Configure barcode reader
BarcodeReader reader = new BarcodeReader();
reader.Pdf417 = true;  // <=== ENABLE 2D Barcode
// reader.DataMatrix = true;
// reader.QR = true;
// Read and process barcodes
Barcode[] barcodes = reader.Read(fileName, pageNumber);
foreach (Barcode bc in barcodes)
  { Console.WriteLine(bc.Text); }

Read barcode in an image zone

A Zone is a rectangular area-of-interest on an image.   To apply operations to a rectangular region of an image set the Zone property of BarcodeReader  Zone setting can be changed at any time.  
Set Zone to new Rectangle() to return to default (entire image) setting.

Read barcode in an image zone Copy Code
// Configure barcode reader. Set direction and expected types
BarcodeReader reader = new BarcodeReader();
reader.Horizontal = true; reader.Vertical = false; reader.Diagonal = false;
reader.Code39 = true;
// Set zone on a page
reader.Zone = new Rectangle(10, 10, 500, 400); // <==== SET ZONE TO READ
// Read and process barcodes
Barcode[] barcodes = reader.Read(fileName, pageNumber);
foreach (Barcode bc in barcodes)
  { Console.WriteLine(bc.Text); }

 

Read barcode from multi-page file Copy Code
 // Configure barcode reader. 
BarcodeReader reader = new BarcodeReader();
reader.Horizontal = true; reader.Vertical = false; reader.Diagonal = false;
reader.Code39 = true; 
// Read and process barcodes
Barcode[] barcodes = reader.Read(fileName); // <=== READ ALL PAGES
foreach (Barcode bc in barcodes)
  { Console.WriteLine ("Page: " + bc.Page.ToString() + " " + bc.Text); }

 

Read barcode with events Copy Code
 
private void _OnBarcodeFound (object sender, BarcodeFoundEventArgs e)
{ 
  Console.WriteLine ("Page: " + e.Barcode.Page.ToString() + " " +   e.Barcode.Text); 
// e.cancel = (e.Count == 3); // Cancel after 3 barcodes are found
}
....

// Configure barcode reader. Set direction and expected types
BarcodeReader reader = new BarcodeReader();
reader.Horizontal = true; reader.Vertical = false; reader.Diagonal = false;
reader.Code39 = true; 
reader.BarcodeFoundEvent +=  // <===  CONFIGURE EVENT HANDLER 
new BarcodeReader.BarcodeFoundEventHandler(_OnBarcodeFound);
// Read and process barcodes
reader.Read(fileName); 

 

© 2007-2013. Inlite Research, Inc. All Rights Reserved.