←Select platform

BarcodeData Class

Summary

Contains the data for a single barcode.

Syntax
C#
VB
Objective-C
C++
Java
[SerializableAttribute()] 
[DataContractAttribute()] 
public class BarcodeData 
<TypeConverterAttribute()> 
<DataContractAttribute()> 
<SerializableAttribute()> 
Public Class BarcodeData  
   Implements System.ICloneable  
@interface LTBarcodeData : NSObject <NSCopying> 
public class 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.

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 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.

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

General

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.

Derived Types

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 Writing Linear 1D Barcodes.

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
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:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
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, LeadRect.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 
c#[Silverlight C# Example] 
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); 
   } 
} 
vb[Silverlight VB Example] 
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 20.0.2020.4.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Barcode Assembly