Error processing SSI file
LEADTOOLS Barcode

Show in webframe
Programming with LEADTOOLS Barcode

LEADTOOLS supports high speed, yet very accurate reading and writing of over 100 different 1D and 2D barcode symbologies (types) and sub-types. The barcodes can be read and written from/to any of the hundreds image file formats supported by LEADTOOLS. For a full list, refer to Summary of All Image File Formats.

Overview of LEADTOOLS Barcode SDK Technology

For more information, refer to:

Startup Up

The LEADTOOLS Barcode support can be accessed through the Leadtools.Barcode.dll assembly (.NET and Silverlight versions are included in your LEADTOOLS installation). The actual barcode symbologies read/write code is included in separate assemblies that are loaded dynamically and accessed at runtime. This minimizes the runtime footprint when certain barcode symbologies and features are not needed by your application. These assemblies are native.NET and Silverlight binaries and can be added directly to your project as references for easy deployment. The following table lists the Barcode support assemblies and their functionality:

Assembly Description
Leadtools.Barcode.OneD.dll

1D Barcodes read/write support

Leadtools.Barcode.DatamatrixRead.dll

Datamatrix barcodes read support

Leadtools.Barcode.DatamatrixWrite.dll

Datamatrix barcodes write support

Leadtools.Barcode.PdfRead.dll

PDF417 and MicroPDF417 barcodes read support

Leadtools.Barcode.PdfWrite.dll

PDF417 and MicroPDF417 barcodes write support

Leadtools.Barcode.QrRead.dll

QR barcodes read support

Leadtools.Barcode.QrWrite.dll

QR barcodes write support

Leadtools.Barcode.Lead2DRead.dll

Aztec, Maxi and MicroQR barcodes read support

Leadtools.Barcode.Lead2DWrite.dll

Aztec, Maxi and MicroQR barcodes write support

For more information, refer to Files To Be Included In Your application.

Refer to the Reading Barcodes and Writing Barcodes tutorials for a step-by-step instruction on how to create a C# or .NET barcode application using LEADTOOLS.

The BarcodeEngine class is the main entry to barcode support in Leadtools.Barcode. Simply create a new instance of this class and then obtain a reference to the BarcodeReader object used to read barcode objects though the BarcodeEngine.Reader property or the BarcodeWriter object used to write barcode objects through the BarcodeEngine.Writer property.

Reading Barcodes

To read barcodes, get an instance to the BarcodeReader object stored in the BarcodeEngine.Reader property then call any of the BarcodeReader.ReadBarcode or BarcodeReader.ReadBarcodes methods passing the RasterImage object containing the image data, an optional search rectangle, optional maximum number of barcodes, optional barcode symbologies (types) and optional extra options. These methods return one or an array of the BarcodeData object containing the barcode data found. Here is an example:


             // Read all barcodes in the image
             BarcodeData[] dataArray = barcodeEngineInstance.Reader.ReadBarcodes(
                theImage,               \\ The RasterImage object
                LogicalRectangle.Empty, \\ Search rectangle, Empty means all image
                0,                      \\ Maximum number of barcodes to return, 0 means all barcodes found
                null);                  \\ Array of BarcodeSymbology we are interested in, null  means all
             

The BarcodeReader.ReadSymbology event is triggered whenever a barcode is found (or when an error occur), you can subscribe to this event to get information about the barcodes being read and to control whether the whole operation should be aborted or continued in case of an error.

The supported barcode types (symbologies) are defined in the BarcodeSymbology enumeration. The following snippet will search and try to read a single QR barcode from the image:


             BarcodeData data = barcodeEngineInstance.Reader.ReadBarcode(
                theImage,               \\ The RasterImage object
                LogicalRectangle.Empty, \\ Search rectangle, Empty means all image
                BarcodeSymbology.QR);   \\ Symbology, only QR
             

Fine tune the barcode reading operation by passing one or more objects derived from BarcodeReadOptions. For example, to change the search direction to both horizontal and vertical barcodes for PDF417, change the default options used by the barcode reader like this:


             // Get the default PDF417 read options
             PDF417BarcodeReadOptions options = barcodeEngineInstance.Reader.GetDefaultOptions(BarcodeSymbology.PDF417);
             // Change the search direction
             options.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;
             // Read a PDF417 barcode from the image
             BarcodeData data = barcodeEngineInstance.Reader.ReadBarcode(theImage, LogicalRectangle.Empty,  BarcodeSymbology.PDF417);
             

Or alternatively, you can pass the options directly to this overload method:


             BarcodeData data = barcodeEngineInstance.Reader.ReadBarcode(theImage, LogicalRectangle.Empty, BarcodeSymbology.PDF417, options);
             

Which only applies these options to this one read operation and not to any subsequent operations.

The BarcodeData object(s) returned from these methods contain the barcodes data found. The BarcodeData.Symbology property will contain the symbology (type) of the barcode found; the BarcodeData.GetData method will return the raw byte array of the barcode data read (with BarcodeData.Value as the string representation of the data). The BarcodeData.Bounds and BarcodeData.RotationAngle will contain the location in pixels and any rotation angle of the barcode found on the image.

When reading some barcode types, extra information may be stored in the barcode other than the data, such as the symbol size of a Datamatrix barcode or the group number of a PDF417 barcode. For these, LEADTOOLS defines derived classes from BarcodeData (DatamatrixBarcodeData and PDF417BarcodeData in the cases mentioned) that contains this extra data. Check if the symbology is of the correct type and then cast the returned BarcodeData object to the derived class type.

Writing Barcodes

To write a barcode to an image, get an instance to the BarcodeWriter object stored in the BarcodeEngine.Writer property, then call BarcodeWriter.WriterBarcode passing the RasterImage object containing the image data to write the barcode to, a BarcodeData object that contains the barcode symbology data and location. Here is an example:


             // Create a UPC A barcode
             BarcodeData data = new BarcodeData();
             data.Symbology = BarcodeSymbology.UPCA;
             data.Value = "01234567890";
             data.Bounds = new LogicalRectangle(10, 10, 600, 200, LogicalUnit.Pixel);
             // Write it with default options
             barcodeEngineInstance.Writer.WriteBarcode(theImage, data, null);
             

Use one or more of the BarcodeWriteOptions derived classes to add extra functionality to the write operation. For example, the following code will cause all subsequent write operations to show the barcode text on the bottom when 1D barcodes are written:


             OneDBarcodeWriteOptions options = barcodeEngineInstance.Writer.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeWriteOptions;
             options.TextPosition = OneDBarcodeTextPosition.Default;
             // Write it with default options
             barcodeEngineInstance.Writer.WriteBarcode(theImage, data, null);
             

Or you can write just this barcode with these options using this:


             barcodeEngineInstance.Writer.WriteBarcode(theImage, data, options);
             

When writing barcodes, you may want to calculate the barcode size in pixels and fine tune the options before committing (for example, change the XModule spacing). Use the BarcodeWriter.CalculateBarcodeDataBounds method to achieve that. This method will fill BarcodeData.Bounds property of the object passed with the size in pixels of the requested barcode with the requested options.

Supported Barcodes Types (Symbologies)

LEADTOOLS supports the reading and writing of several major types of barcodes. These types include:

The individual supported symbologies are defined by the BarcodeSymbology enumeration.

For each major type of barcode, one or more subtypes are supported for both reading and writing. These subtypes are:

Linear (1D) Barcodes:

2D

For description and visual samples of the barcode symbologies supported by LEADTOOLS, refer to Supported Barcode Symbologies.

See Also

Reference

UPC / EAN Barcodes in LEADTOOLS
2 of 5 Barcodes in LEADTOOLS
GS1 Databar / RSS-14 Barcodes in LEADTOOLS
Code 128 Barcodes in LEADTOOLS
USPS and 4-State Barcodes in LEADTOOLS
MSI Barcodes (Pulse Width Modulated) in LEADTOOLS
Codabar Barcodes in LEADTOOLS
Miscellaneous Barcodes in LEADTOOLS
Datamatrix Barcodes in LEADTOOLS
PDF417 and MicroPDF417 Barcodes in LEADTOOLS
MicroPDF417 Barcodes in LEADTOOLS
QR Barcodes in LEADTOOLS
Writing Barcodes - Bounds and XModule

Error processing SSI file