public class BarcodeReadSymbologyEventArgs : EventArgs
You can use the ReadSymbology event to obtain information and set the status of the current barcode reading operation.
When reading barcodes using BarcodeReader.ReadBarcode or BarcodeReader.ReadBarcodes, the BarcodeReader object will fire the ReadSymbology event multiple times depending on the symbologies being read.
LEADTOOLS barcode reading is designed for speed and multiple barcode symbologies can be read (or searched for) in one operation as these barcodes share similar characteristics. Therefore, the symbologies being read are stored in a BarcodeSymbology array and can be obtained with the BarcodeReadSymbologyEventArgs.GetSymbologies method.
The following table lists the event members and their meanings:
Member | Description |
---|---|
Operation |
Can be either BarcodeReadSymbologyOperation.PreRead if the BarcodeReader is about to try reading the symbologies or BarcodeReadSymbologyOperation.PreRead when the reader has finished reading the objects. |
GetSymbologies |
Will return the current symbologies being searched for or that have been read. |
Options |
The BarcodeReadOptions or one of its derived classes that specify the options being used to read the symbologies. This could be the options passed through the read methods or the default options set in BarcodeReader. |
Data |
A BarcodeData object that contains the data of the barcode found. Only valid if Operation is BarcodeReadSymbologyOperation.PostRead and no error occurred. Otherwise, it will be null (Nothing in Visual Basic). |
Error |
An Exception object that contains any error encountered during the current operation. If no errors are encountered, then this member will be null (Nothing in Visual Basic). |
Status |
The status of the operation. The BarcodeReader will always set this member to BarcodeReadSymbologyEventArgs.Continue, which means proceed to the next phase of the read operation. You can set this member to BarcodeReadSymbologyStatus.Skip to skip reading the current symbologies (only when Operation is BarcodeReadSymbologyOperation.PreRead) or to abort the whole read operation by setting it to BarcodeReadSymbologyStatus.Abort. |
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Barcode;
using Leadtools.ImageProcessing;
public void BarcodeReader_ReadSymbologyExample()
{
string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif");
// Create a Barcode engine
BarcodeEngine engine = new BarcodeEngine();
// Get the Barcode reader instance
BarcodeReader reader = engine.Reader;
// Load the image
using (RasterCodecs codecs = new RasterCodecs())
{
using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
{
// Subscribe to the ReadSymbology event
reader.ReadSymbology += new EventHandler<BarcodeReadSymbologyEventArgs>(reader_ReadSymbology);
// Read all barcodes in the image
reader.ReadBarcodes(image, LeadRect.Empty, 0, null);
reader.ReadSymbology -= new EventHandler<BarcodeReadSymbologyEventArgs>(reader_ReadSymbology);
}
}
}
private void reader_ReadSymbology(object sender, BarcodeReadSymbologyEventArgs e)
{
if (e.Operation == BarcodeReadSymbologyOperation.PreRead)
{
// Before reading, show the symbologies the engine is going to try to read
Console.WriteLine("Trying to read the following symbologies:");
BarcodeSymbology[] symbologies = e.GetSymbologies();
for (int i = 0; i < symbologies.Length; i++)
{
Console.Write(symbologies[i]);
if (i != (symbologies.Length - 1))
{
Console.Write(", ");
Console.WriteLine(e.Options.FriendlyName);
}
else
{
Console.WriteLine();
}
}
}
else if (e.Operation == BarcodeReadSymbologyOperation.PostRead)
{
if (e.Error == null)
{
// No errors
BarcodeData barcode = e.Data;
if (barcode != null)
{
// Found a barcode, show it
Console.WriteLine(" {0} at {1} with data {2}", barcode.Symbology, barcode.Bounds, barcode.Value);
}
else
{
Console.WriteLine(" No barcodes found");
}
}
else
{
// Show the error
Console.WriteLine("Error: {0}", e.Error.Message);
// Tell the reader top stop reading barcodes
e.Status = BarcodeReadSymbologyStatus.Abort;
}
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}