[SerializableAttribute()]
[DataContractAttribute()]
public class BarcodeData
The BarcodeData class contains the data for a single barcode. It is used by LEADTOOLS when reading and writing barcodes from/to an image.
The BarcodeReader class contains multiple methods to read a single or multiple barcodes from an image ( Refer to the BarcodeReader.ReadBarcode and BarcodeReader.ReadBarcodes methods). For each barcode found, BarcodeReader will return an instance of BarcodeData populated with the data found in the barcode.
Refer to BarcodeData Class Members for a list of 'BarcodeData' members and their meaning when BarcodeReader returns the object from an image.
In addition to the members above, other read options not related to the barcode data can be set using the BarcodeReadOptions class or one of its derived classes.
For a tutorial, refer to one of the Extract Barcodes Tutorials.
The BarcodeWriter class allows you to write a single barcode to the image. You must create a new instance of the BarcodeData class, fill its members with the values for the new barcode and call the WriteBarcode method passing the created object.
Refer to BarcodeData Class Members for a list of 'BarcodeData' members of BarcodeData and their meaning when writing barcodes.
In addition to the members above, other write options not related to the barcode data can be set using the BarcodeWriteOptions class or one of its derived classes.
You can also use the BarcodeWriter.CalculateBarcodeDataBounds method to pre-calculate the barcode location and size based on the barcode data, its "XModule" and various other properties.
For a tutorial on writing barcodes, refer to Write Barcodes Tutorials.
The BarcodeData class contains support for the following:
Serialization of an array of BarcodeData to and from XML through the BarcodeData.Save and BarcodeData.Load methods.
Cloning by implementing the standard .NET ICloneable interface and implementing the BarcodeData.Clone method.
Creating of a default and valid (with legal values for the data) instance for a certain symbology using the CreateDefaultBarcodeData method. This can be useful when debugging barcode writing.
LEADTOOLS provides derived classes that contain extra barcode data information. Derived types contain specialized data not available in BarcodeData.
When the BarcodeReader class encounters a barcode of one of these symbologies, it returns one of the derived types casted down as BarcodeData. You can then cast the object up to its derived type if needed, refer to any of the classes listed in the table below.
The following table lists the derived types:
Type | Description |
---|---|
AztecBarcodeData | Used with BarcodeSymbology.Aztec |
DatamatrixBarcodeData | Used with BarcodeSymbology.Datamatrix. Adds the Datamatrix barcode symbol size to be used when reading and writing |
MaxiBarcodeData | Used with BarcodeSymbology.Maxi |
MicroPDF417BarcodeData | Used with BarcodeSymbology.MicroPDF417. Adds the MicroPDF417 data code to be used when reading and writing. Also, contains information on whether a MicroPDF417 barcode read is linked to a linear barcode below it |
MicroQRBarcodeData | Used with BarcodeSymbology.MicroQR |
PDF417BarcodeData | Used with BarcodeSymbology.PDF417. Contains information about the group number of a PDF417 barcode found in the image |
QRBarcodeData | Used with BarcodeSymbology.QR. Adds the QR barcode symbol size to be used when reading and writing |
When reading barcodes, you can use the base BarcodeData class exclusively only when you are interested in the extra options. Generally, all the relevant data of the barcode read can be obtained with BarcodeData.GetData or BarcodeData.Value. If you are however interested in reading those extra values, then simple cast the object up to the correct derived class and read the extra properties.
When writing barcodes, you must generally always pass a derived class since all information is needed when writing a barcode. Create an instance of the correct derived class and pass it to BarcodeWriter.WriteBarcode. This method will take the data as a base BarcodeData instance and will accept passing generic BarcodeData objects when writing more specific barcodes (such as QR) although this is generally not a recommended process.
The GetBarcodeDataType returns the Type of the derived BarcodeData class associated with a certain BarcodeSymbology or the BarcodeData type when the symbology does not have a specialized data class.
The color of the barcode is not considered part of its data. Colors of barcode read can be controlled through the BarcodeReadOptions.ForeColor and BarcodeReadOptions.BackColor properties. Also colors of barcodes to be written can be set through BarcodeWriteOptions.ForeColor and BarcodeWriteOptions.BackColor.
Some barcodes like QR and PDF417 support data that is not necessarily ASCII text. For example, an image, a URL or just raw stream of bytes. When reading these barcodes, the Value property may not return an accurate representation of the data. Hence, use the BarcodeData.GetData method and then parse it. Also, when writing barcodes, you must set the raw data using the SetData method.
The Australian post barcode (BarcodeSymbology.AustralianPost4State) string has a special format to distinguish different fields (i.e. FCC, DPID, and CIF). The string format puts dashes between fields as follows: "FCC-DIPD-CIF", where FCC is a 2-digit field (valid values are 11, 87, 45, 92, 59, 62, and 44), DPID is an 8-digit field representing the address, and CIF (optional) represents the customer information field. For more information, refer to the standard. This string format applies for both read and write.
GS1 Databar Expanded (BarcodeSymbology.GS1DatabarExpanded) and GS1 Databar Expanded Stacked (BarcodeSymbology.GS1DatabarExpandedStaceked) barcode strings need to be written conforming to a string format that indicates a particular encoding method, such as Method "1", Method "0100", Method "0101", … etc. For example, a string (01)00012345678905(10)ABC123" is encoded using Method "1" (i.e. General Identification Data). Note that the 14th digit of the item identification number (in this case, "5"), if it exists, is considered as a check digit and is ignored. A string that is written without following any of these special encoding formats will be encoded by Method "00" (i.e. General Purpose Data).
When a BarcodeData is returned from a read operation, an extra digit in curly brackets (i.e. "{" and "}") is added to indicate the linkage bit at the beginning of the string. The curly brackets are not part of the encoded barcode data, and are not defined in the standard. Rather, they distinguish the linkage digit from other data. For example, if a barcode is written with string "(01)00012345678905(10)ABC123" while the linkage bit is set to zero, the read function result will be "{0}(01)00012345678905(10)ABC123", where {0} is the linkage digit and the remaining characters are the barcode data.
BarcodeSymbology.UCCEAN128 is designed for reading UCCEAN 128 barcode only, and it is not designed for writing this barcode type.
Code Interleaved 2 of 5: I = # of digits and must be even.
Linear (1D) barcodes are not supported in UNICODE.
For a table containing information useful when writing 1D barcode data see Writing Linear 1D Barcodes.
This example reads the first barcode found in an image and shows the various data values. For an example on writing barcodes, refer to BarcodeWriter.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Barcode;
using Leadtools.ImageProcessing;
public void BarcodeData_Example()
{
string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif");
// Create a Barcode engine
BarcodeEngine engine = new BarcodeEngine();
// Load the image
using (RasterCodecs codecs = new RasterCodecs())
{
using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
{
// Read the first barcode
BarcodeData data = engine.Reader.ReadBarcode(image, LeadRect.Empty, BarcodeSymbology.Unknown);
// Show the barcode data found (if any)
if (data != null)
{
Console.WriteLine("Found barcode at {0}", data.Bounds);
Console.WriteLine("Symbology: {0}", data.Symbology);
Console.WriteLine("Data: {0}", data.Value);
}
}
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
}
Programming with LEADTOOLS Barcode
UPC / EAN 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
Miscellaneous Barcodes in LEADTOOLS
Datamatrix Barcodes in LEADTOOLS
PDF417 and MicroPDF417 Barcodes in LEADTOOLS