←Select platform

BarcodeData Class

Summary

Contains the data for a single barcode.

Syntax

C#
VB
Java
Objective-C
WinRT C#
C++
[SerializableAttribute()] 
[DataContractAttribute()] 
public class BarcodeData 
<TypeConverterAttribute()> 
<DataContractAttribute()> 
<SerializableAttribute()> 
Public Class BarcodeData  
   Implements System.ICloneable  
public sealed class BarcodeData : System.ICloneable   
@interface LTBarcodeData : NSObject <NSCopying> 
public class BarcodeData 
function Leadtools.Barcode.BarcodeData() 
[TypeConverterAttribute()] 
[DataContractAttribute()] 
[SerializableAttribute()] 
public ref class BarcodeData : public System.ICloneable   

Remarks

The BarcodeData class contains the data for a single barcode. It is used by LEADTOOLS when reading and writing barcodes from/to an image.

Reading Barcodes

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.

The following table lists the members of BarcodeData and their meaning when BarcodeReader returns the object from an image:

Member Description
Symbology

A member of the BarcodeSymbology enumeration that specifies the symbology (or type) of the barcode found

Bounds

The barcode location and size in the image

RotationAngle

The angle of rotation if the barcode was rotated (or skewed)

BarWidthReduction

The bar width reduction value of the barcode in micrometer when reading 1D barcodes.

The data (accessed through GetData)

The raw data found inside the barcode as a byte array

Value

A string representation (in ASCII) of the data. The value returned is simply an ASCII text of the byte array returned from GetData

Tag

User defined field. Not used

DatamatrixSymbolSize

An DatamatrixBarcodeSymbolSize enumeration member that specifies the symbol size of the Datamatrix barcode.

MicroPDF417IsLinked

Indicates that the MicroPDF417 barcode is linked to a linear symbol printed below it.

MicroPDF417DataCode

The MicroPDF417 barcode function code word for Code 128 emulation.

PDF417Group

The group number if this PDF417 barcode symbol is a member of a group of symbols

QRSymbolModel

An QRBarcodeSymbolModel enumeration member that specifies the symbol model and version of the QR barcode.

AztecSymbolModel

An AztecBarcodeSymbolModel enumeration member that determines the symbol size to use when writing an Aztec barcode.

MaxiSymbolModel

An MaxiBarcodeSymbolModel enumeration member that determines the encoding mode to use when writing a Maxi Code barcode.

MicroQRSymbolModel

An MicroQRBarcodeSymbolModel enumeration member that determines the symbol size to use when writing a MicroQR barcode.

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 on reading barcodes, refer to Reading Barcodes Tutorial.

Writing Barcodes

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.

The following table lists the members of BarcodeData and their meaning when writing barcodes:

Member Description
Symbology

A member of the BarcodeSymbology enumeration that specifies the symbology (or type) of the barcode to write.

Bounds

The location and size where to write the barcode in the image.

The data (set through SetData).

The raw data of the new barcode as a byte array.

Value

A string representation (in ASCII) of the data. The value set in Value will simply be parsed as ASCII text and put it in the raw data through SetData

RotationAngle

Not used in writing

BarWidthReduction

Not used in writing

Tag

User defined field. Not used

DatamatrixSymbolSize

A member of the DatamatrixBarcodeSymbolSize enumeration that specifies the symbol size of the barcode to write

MicroPDF417IsLinked

Indicates whether the MicroPDF417 barcode is linked to a linear symbol printed below it, To link MicroPDF417 when writing, use the MicroPDF417BarcodeWriteOptions.IsLinked property.

MicroPDF417DataCode

Indicates the MicroPDF417 barcode function code word for Code 128 emulation, to use this value when writing MicroPDF417 symbols, set the value of MicroPDF417BarcodeWriteOptions.EnableGroupMode to true

PDF417Group

Specifies whether this PDF417 barcode symbol is a member of a group of symbols, To use this value when writing PDF417 symbols you must set the value of PDF417BarcodeWriteOptions.EnableGroupMode to true

QRSymbolModel

A QRBarcodeSymbolModel enumeration member that specifies the QR barcode symbol model and version.

AztecSymbolModel

A AztecBarcodeSymbolModel enumeration member that specifies the Aztec barcode symbol size.

MaxiSymbolModel

A MaxiBarcodeSymbolModel enumeration member that specifies the Maxi barcode symbol mode.

MicroQRSymbolModel

A MicroQRBarcodeSymbolModel enumeration member that specifies the MicroQR barcode symbol size.

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 Writing Barcodes Tutorial.

General

Note: This section is not supported in LEADTOOLS for Windows Runtime.

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.

Note: The functionality in the above list is not supported in LEADTOOLS for Windows Runtime.

Derived Types

Note: This section is not supported in LEADTOOLS for Windows Runtime.

This section deals with derived barcode data types only currently available in the following symbologies: BarcodeSymbology.Datamatrix, BarcodeSymbology.MicroPDF417, BarcodeSymbology.PDF417 and BarcodeSymbology.QR. All other symbology types do not contain specialized data types and the base BarcodeData must be used exclusively when reading or writing barcodes.

Some barcode symbologies contain extra information that are not available in BarcodeData, for these types, LEADTOOLS adds derived classes to contain the extra information.

When the BarcodeReader class encounters a barcode of one of these symbologies, it returns one of the following 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 for an example.

The following table lists the derived types:

Type Description
DatamatrixBarcodeData

Used with BarcodeSymbology.Datamatrix. Adds the Datamatrix barcode symbol size to be used when reading and writing

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

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.

Notes

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 necessary 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, please 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 https://www.leadtools.com/sdk/barcode/1d-chart.

Example

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.

C#
VB
Silverlight C#
Silverlight VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Forms; 
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, LogicalRectangle.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:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Forms 
Imports Leadtools.Barcode 
Imports Leadtools.ImageProcessing 
 
Public Sub BarcodeData_Example() 
   Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif") 
 
   ' Create a Barcode engine 
   Dim engine As New BarcodeEngine() 
 
   ' Load the image 
   Using codecs As New RasterCodecs() 
      Using image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1) 
         ' Read the first barcode 
         Dim data As BarcodeData = engine.Reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.Unknown) 
 
         ' Show the barcode data found (if any) 
         If Not IsNothing(data) Then 
            Console.WriteLine("Found barcode at {0}", data.Bounds) 
            Console.WriteLine("Symbology: {0}", data.Symbology) 
            Console.WriteLine("Data: {0}", data.Value) 
         End If 
      End Using 
   End Using 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Forms; 
using Leadtools.Barcode; 
using Leadtools.ImageProcessing; 
using Leadtools.Examples; 
 
public void BarcodeData_Example(RasterImage image) 
{ 
   // Create a Barcode engine 
   BarcodeEngine engine = new BarcodeEngine(); 
 
   // Load the image 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Read the first barcode 
   BarcodeData data = engine.Reader.ReadBarcode(image, LogicalRectangle.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); 
   } 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Forms 
Imports Leadtools.Barcode 
Imports Leadtools.ImageProcessing 
 
Public Sub BarcodeData_Example(ByVal image As RasterImage) 
   ' Create a Barcode engine 
   Dim engine As BarcodeEngine = New BarcodeEngine() 
 
   ' Load the image 
   Dim codecs As RasterCodecs = New RasterCodecs() 
 
   ' Read the first barcode 
   Dim data As BarcodeData = engine.Reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.Unknown) 
 
   ' Show the barcode data found (if any) 
   If Not data Is Nothing Then 
      Console.WriteLine("Found barcode at {0}", data.Bounds) 
      Console.WriteLine("Symbology: {0}", data.Symbology) 
      Console.WriteLine("Data: {0}", data.Value) 
   End If 
End Sub 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Barcode Assembly