←Select platform

DatamatrixBarcodeData Class

Summary

Contains the data for a single Datamatrix barcode.

Syntax

C#
VB
Java
Objective-C
C++
[SerializableAttribute()] 
public class DatamatrixBarcodeData : BarcodeData 

<TypeConverterAttribute()> 
<SerializableAttribute()> 
Public Class DatamatrixBarcodeData  
   Inherits BarcodeData 
   Implements System.ICloneable  

@interface LTDatamatrixBarcodeData : LTBarcodeData <NSCopying> 

public class DatamatrixBarcodeData extends BarcodeData 

[TypeConverterAttribute()] 
[SerializableAttribute()] 
public ref class DatamatrixBarcodeData : public BarcodeData, System.ICloneable   

Remarks

The DatamatrixBarcodeData class derives from the base BarcodeData to add specific data that can be read or written when using Datamatrix barcodes.

Reading Barcodes

When the BarcodeReader object detects and reads a Datamatrix ( BarcodeSymbology.Datamatrix), the BarcodeReader.ReadBarcode and BarcodeReader.ReadBarcodes methods will return the DatamatrixBarcodeData object for each barcode cast down to the base BarcodeData class.

You can perform standard .NET casting to get the object as DatamatrixBarcodeData and then examine the extra data properties associated with it.

In addition to all the data members returned as usual in the base BarcodeData object, this class adds the following members:

In addition to the members above, other Datamatrix read options not related to the barcode data can be set using the DatamatrixBarcodeReadOptions class.

Writing Barcodes

The BarcodeWriter class contains the WriteBarcode method that is used to write a barcode to an image. This method accepts the data parameter as the base BarcodeData object. To write a Datamatrix barcode, create an instance of DatamatrixBarcodeData and fill the required parameters, then pass this object as the data parameter to WriteBarcode.

In addition to all the data members that must be set as usual in the base BarcodeData object, also specify the following members:

In addition to the members above, other Datamatrix write options not related to the barcode data can be set using the DatamatrixBarcodeWriteOptions class.

You can use the static (or Shared in VB) BarcodeData.CreateDefaultBarcodeData method to create a new instance of DatamatrixBarcodeData that contains default parameters ready for writing to an image:

VB Snippet
Dim datamatrixData As DatamatrixBarcodeData = DirectCast(BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.Datamatrix), DatamatrixBarcodeData) 
C# Snippet
DatamatrixBarcodeData datamatrixData = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.Datamatrix) as DatamatrixBarcodeData; 

Example

This example writes a couple of Datamatrix barcodes with different options to an image and then reads them back.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Barcode; 
using Leadtools.ImageProcessing; 
 
public void DatamatrixBarcode_Example() 
{ 
   string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "MyDatamatrixBarcodes.tif"); 
 
   BarcodeEngine engine = new BarcodeEngine(); 
 
   // Create the image to write the barcodes to 
   int resolution = 300; 
   using (RasterImage image = RasterImage.Create((int)(8.5 * resolution), (int)(11.0 * resolution), 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White))) 
   { 
      // Write two Datamatrix barcodes, a square and a rectangle one 
      WriteBarcode(engine.Writer, image, DatamatrixBarcodeSymbolSize.Size16X36, "Datamatrix1 16x36", false); 
      WriteBarcode(engine.Writer, image, DatamatrixBarcodeSymbolSize.Size132X132, "Datamatrix2 132x132", true); 
 
      // Save the image 
      using (RasterCodecs codecs = new RasterCodecs()) 
      { 
         codecs.Save(image, imageFileName, RasterImageFormat.CcittGroup4, 1); 
      } 
   } 
 
   // Now read the barcodes again 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      using (RasterImage image = codecs.Load(imageFileName)) 
      { 
         // Read only square symbols, should only read the first barcode 
         ReadBarcodes(engine.Reader, image, true); 
 
         // Read all symbols, should read both barcodes 
         ReadBarcodes(engine.Reader, image, false); 
      } 
   } 
} 
 
private void WriteBarcode(BarcodeWriter writer, RasterImage image, DatamatrixBarcodeSymbolSize symbolSize, string value, bool topLeft) 
{ 
   // Create the barcode data 
   DatamatrixBarcodeData barcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.Datamatrix) as DatamatrixBarcodeData; 
   barcode.SymbolSize = symbolSize; 
   barcode.Value = value; 
 
   // We will use the alignment to position the barcodes, so use all of the image 
   barcode.Bounds = new LeadRect(0, 0, image.ImageWidth, image.ImageHeight); 
 
   // Set the write options 
   DatamatrixBarcodeWriteOptions options = new DatamatrixBarcodeWriteOptions(); 
 
   if (topLeft) 
   { 
      options.HorizontalAlignment = BarcodeAlignment.Near; 
      options.VerticalAlignment = BarcodeAlignment.Near; 
   } 
   else 
   { 
      options.HorizontalAlignment = BarcodeAlignment.Far; 
      options.VerticalAlignment = BarcodeAlignment.Far; 
   } 
 
   options.DisableCompression = false; 
   options.GroupNumber = 0; 
   options.GroupTotal = 0; 
   options.FileIdNumberLowByte = 1; 
   options.FileIdNumberHighByte = 1; 
   options.XModule = 30; 
 
   // Write it 
   Console.WriteLine("Writing barcode with symbol size: {0} and Data: {1}", symbolSize, value); 
   writer.WriteBarcode(image, barcode, options); 
} 
 
private void ReadBarcodes(BarcodeReader reader, RasterImage image, bool squareOnly) 
{ 
   // Setup read options 
   DatamatrixBarcodeReadOptions options = new DatamatrixBarcodeReadOptions(); 
   options.ReadSquareSymbolsOnly = squareOnly; 
   options.EnableDoublePass = false; 
   options.EnableInvertedSymbols = false; 
   options.EnableFastMode = true; 
   options.EnableSmallSymbols = true; 
 
   Console.WriteLine("Reading Datamatrix barcodes with ReadSquareSymbolsOnly set to {0}", squareOnly); 
   BarcodeData[] barcodes = reader.ReadBarcodes(image, LeadRect.Empty, 0, new BarcodeSymbology[] { BarcodeSymbology.Datamatrix }, new BarcodeReadOptions[] { options }); 
   Console.WriteLine("{0} barcodes found:", barcodes.Length); 
   foreach (DatamatrixBarcodeData barcode in barcodes) 
   { 
      Console.WriteLine(" At {0}, symbol size: {1} and data: {2}", barcode.Bounds, barcode.SymbolSize, barcode.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 DatamatrixBarcode_Example() 
   Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "MyDatamatrixBarcodes.tif") 
 
   Dim engine As New BarcodeEngine() 
 
   ' Create the image to write the barcodes to 
   Dim resolution As Integer = 300 
   Using image As RasterImage = RasterImage.Create(CType(8.5 * resolution, Integer), CType(11.0 * resolution, Integer), 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White)) 
      ' Write two Datamatrix barcodes, a square and a rectangle one 
      WriteBarcode(engine.Writer, image, DatamatrixBarcodeSymbolSize.Size16X36, "Datamatrix1 16x36", False) 
      WriteBarcode(engine.Writer, image, DatamatrixBarcodeSymbolSize.Size132X132, "Datamatrix2 132x132", True) 
 
      ' Save the image 
      Using codecs As New RasterCodecs() 
         codecs.Save(image, imageFileName, RasterImageFormat.CcittGroup4, 1) 
      End Using 
   End Using 
 
   ' Now read the barcodes again 
   Using codecs As New RasterCodecs() 
      Using image As RasterImage = codecs.Load(imageFileName) 
         ' Read only square symbols, should only read the first barcode 
         ReadBarcodes(engine.Reader, image, True) 
 
         ' Read all symbols, should read both barcodes 
         ReadBarcodes(engine.Reader, image, False) 
      End Using 
   End Using 
End Sub 
 
Private Sub WriteBarcode(ByVal writer As BarcodeWriter, ByVal image As RasterImage, ByVal symbolSize As DatamatrixBarcodeSymbolSize, ByVal value As String, ByVal topLeft As Boolean) 
   ' Create the barcode data 
   Dim barcode As DatamatrixBarcodeData = DirectCast(BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.Datamatrix), DatamatrixBarcodeData) 
   barcode.SymbolSize = symbolSize 
   barcode.Value = value 
 
   ' We will use the alignment to position the barcodes, so use all of the image 
   barcode.Bounds = New LeadRect(0, 0, image.ImageWidth, image.ImageHeight) 
 
   ' Set the write options 
   Dim options As New DatamatrixBarcodeWriteOptions() 
 
   If topLeft Then 
      options.HorizontalAlignment = BarcodeAlignment.Near 
      options.VerticalAlignment = BarcodeAlignment.Near 
   Else 
      options.HorizontalAlignment = BarcodeAlignment.Far 
      options.VerticalAlignment = BarcodeAlignment.Far 
   End If 
 
   options.DisableCompression = False 
   options.GroupNumber = 0 
   options.GroupTotal = 0 
   options.FileIdNumberLowByte = 1 
   options.FileIdNumberHighByte = 1 
   options.XModule = 30 
 
   ' Write it 
   Console.WriteLine("Writing barcode with symbol size: {0} and Data: {1}", symbolSize, value) 
   writer.WriteBarcode(image, barcode, options) 
End Sub 
 
Private Sub ReadBarcodes(ByVal reader As BarcodeReader, ByVal image As RasterImage, ByVal squareOnly As Boolean) 
   ' Setup read options 
   Dim options As New DatamatrixBarcodeReadOptions() 
   options.ReadSquareSymbolsOnly = squareOnly 
   options.EnableDoublePass = False 
   options.EnableInvertedSymbols = False 
   options.EnableFastMode = True 
   options.EnableSmallSymbols = True 
 
   Console.WriteLine("Reading Datamatrix barcodes with ReadSquareSymbolsOnly set to {0}", squareOnly) 
   Dim barcodes() As BarcodeData = reader.ReadBarcodes(image, LeadRect.Empty, 0, New BarcodeSymbology() {BarcodeSymbology.Datamatrix}, New BarcodeReadOptions() {options}) 
   Console.WriteLine("{0} barcodes found:", barcodes.Length) 
   For Each barcode As DatamatrixBarcodeData In barcodes 
      Console.WriteLine(" At {0}, symbol size: {1} and data: {2}", barcode.Bounds, barcode.SymbolSize, barcode.Value) 
   Next 
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 DatamatrixBarcode_Example(RasterImage image, Stream outStream) 
{ 
   BarcodeEngine engine = new BarcodeEngine(); 
 
   // Create the image to write the barcodes to 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Write two Datamatrix barcodes, a square and a rectangle one 
   WriteBarcode(engine.Writer, image, DatamatrixBarcodeSymbolSize.Size16X36, "Datamatrix1 16x36", false); 
   WriteBarcode(engine.Writer, image, DatamatrixBarcodeSymbolSize.Size132X132, "Datamatrix2 132x132", true); 
 
   // Save the image 
   codecs.Save(image, outStream, RasterImageFormat.CcittGroup4, 1); 
 
   // Now read the barcodes again 
   // Read only square symbols, should only read the first barcode 
   ReadBarcodes(engine.Reader, image, true); 
 
   // Read all symbols, should read both barcodes 
   ReadBarcodes(engine.Reader, image, false); 
} 
 
private void WriteBarcode(BarcodeWriter writer, RasterImage image, DatamatrixBarcodeSymbolSize symbolSize, string value, bool topLeft) 
{ 
   // Create the barcode data 
   DatamatrixBarcodeData barcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.Datamatrix) as DatamatrixBarcodeData; 
   barcode.SymbolSize = symbolSize; 
   barcode.Value = value; 
 
   // We will use the alignment to position the barcodes, so use all of the image 
   barcode.Bounds = new LogicalRectangle(0, 0, image.ImageWidth, image.ImageHeight, LogicalUnit.Pixel); 
 
   // Set the write options 
   DatamatrixBarcodeWriteOptions options = new DatamatrixBarcodeWriteOptions(); 
 
   if (topLeft) 
   { 
      options.HorizontalAlignment = BarcodeAlignment.Near; 
      options.VerticalAlignment = BarcodeAlignment.Near; 
   } 
   else 
   { 
      options.HorizontalAlignment = BarcodeAlignment.Far; 
      options.VerticalAlignment = BarcodeAlignment.Far; 
   } 
 
   options.DisableCompression = false; 
   options.GroupNumber = 0; 
   options.GroupTotal = 0; 
   options.FileIdNumberLowByte = 1; 
   options.FileIdNumberHighByte = 1; 
   options.XModule = 30; 
 
   // Write it 
   Console.WriteLine("Writing barcode with symbol size: {0} and Data: {1}", symbolSize, value); 
   writer.WriteBarcode(image, barcode, options); 
} 
 
private void ReadBarcodes(BarcodeReader reader, RasterImage image, bool squareOnly) 
{ 
   // Setup read options 
   DatamatrixBarcodeReadOptions options = new DatamatrixBarcodeReadOptions(); 
   options.ReadSquareSymbolsOnly = squareOnly; 
   options.EnableDoublePass = false; 
   options.EnableInvertedSymbols = false; 
   options.EnableFastMode = true; 
   options.EnableSmallSymbols = true; 
 
   Console.WriteLine("Reading Datamatrix barcodes with ReadSquareSymbolsOnly set to {0}", squareOnly); 
   BarcodeData[] barcodes = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, new BarcodeSymbology[] { BarcodeSymbology.Datamatrix }, new BarcodeReadOptions[] { options }); 
   Console.WriteLine("{0} barcodes found:", barcodes.Length); 
   foreach (DatamatrixBarcodeData barcode in barcodes) 
   { 
      Console.WriteLine(" At {0}, symbol size: {1} and data: {2}", barcode.Bounds, barcode.SymbolSize, barcode.Value); 
   } 
} 
vb[Silverlight VB Example] 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Forms 
Imports Leadtools.Barcode 
Imports Leadtools.ImageProcessing 
 
Public Sub DatamatrixBarcode_Example(ByVal image As RasterImage, ByVal outStream As Stream) 
   Dim engine As BarcodeEngine = New BarcodeEngine() 
 
   ' Create the image to write the barcodes to 
   Dim codecs As RasterCodecs = New RasterCodecs() 
 
   ' Write two Datamatrix barcodes, a square and a rectangle one 
   WriteBarcode(engine.Writer, image, DatamatrixBarcodeSymbolSize.Size16X36, "Datamatrix1 16x36", False) 
   WriteBarcode(engine.Writer, image, DatamatrixBarcodeSymbolSize.Size132X132, "Datamatrix2 132x132", True) 
 
   ' Save the image 
   codecs.Save(image, outStream, RasterImageFormat.CcittGroup4, 1) 
 
   ' Now read the barcodes again 
   ' Read only square symbols, should only read the first barcode 
   ReadBarcodes(engine.Reader, image, True) 
 
   ' Read all symbols, should read both barcodes 
   ReadBarcodes(engine.Reader, image, False) 
End Sub 
 
Private Sub WriteBarcode(ByVal writer As BarcodeWriter, ByVal image As RasterImage, ByVal symbolSize As DatamatrixBarcodeSymbolSize, ByVal value As String, ByVal topLeft As Boolean) 
   ' Create the barcode data 
   Dim barcode As DatamatrixBarcodeData = TryCast(BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.Datamatrix), DatamatrixBarcodeData) 
   barcode.SymbolSize = symbolSize 
   barcode.Value = value 
 
   ' We will use the alignment to position the barcodes, so use all of the image 
   barcode.Bounds = New LogicalRectangle(0, 0, image.ImageWidth, image.ImageHeight, LogicalUnit.Pixel) 
 
   ' Set the write options 
   Dim options As DatamatrixBarcodeWriteOptions = New DatamatrixBarcodeWriteOptions() 
 
   If topLeft Then 
      options.HorizontalAlignment = BarcodeAlignment.Near 
      options.VerticalAlignment = BarcodeAlignment.Near 
   Else 
      options.HorizontalAlignment = BarcodeAlignment.Far 
      options.VerticalAlignment = BarcodeAlignment.Far 
   End If 
 
   options.DisableCompression = False 
   options.GroupNumber = 0 
   options.GroupTotal = 0 
   options.FileIdNumberLowByte = 1 
   options.FileIdNumberHighByte = 1 
   options.XModule = 30 
 
   ' Write it 
   Console.WriteLine("Writing barcode with symbol size: {0} and Data: {1}", symbolSize, value) 
   writer.WriteBarcode(image, barcode, options) 
End Sub 
 
Private Sub ReadBarcodes(ByVal reader As BarcodeReader, ByVal image As RasterImage, ByVal squareOnly As Boolean) 
   ' Setup read options 
   Dim options As DatamatrixBarcodeReadOptions = New DatamatrixBarcodeReadOptions() 
   options.ReadSquareSymbolsOnly = squareOnly 
   options.EnableDoublePass = False 
   options.EnableInvertedSymbols = False 
   options.EnableFastMode = True 
   options.EnableSmallSymbols = True 
 
   Console.WriteLine("Reading Datamatrix barcodes with ReadSquareSymbolsOnly set to {0}", squareOnly) 
   Dim barcodes As BarcodeData() = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, New BarcodeSymbology() {BarcodeSymbology.Datamatrix}, New BarcodeReadOptions() {options}) 
   Console.WriteLine("{0} barcodes found:", barcodes.Length) 
   For Each barcode As DatamatrixBarcodeData In barcodes 
      Console.WriteLine(" At {0}, symbol size: {1} and data: {2}", barcode.Bounds, barcode.SymbolSize, barcode.Value) 
   Next barcode 
End Sub 

Requirements

Target Platforms

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

Leadtools.Barcode Assembly