←Select platform

DatamatrixBarcodeData Class

Summary
Contains the data for a single Datamatrix barcode.
Syntax
C#
Objective-C
C++/CLI
Java
Python
[SerializableAttribute()] 
public class DatamatrixBarcodeData : BarcodeData 
@interface LTDatamatrixBarcodeData : LTBarcodeData<NSCopying> 
public class DatamatrixBarcodeData extends BarcodeData 
[TypeConverterAttribute()] 
[SerializableAttribute()] 
public ref class DatamatrixBarcodeData : public BarcodeData, System.ICloneable   
class DatamatrixBarcodeData(BarcodeData): 
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[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#
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; 
   barcode.Symbology= BarcodeSymbology.Datamatrix; 
 
   // 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; 
   options.HRItoGS1 = false; 
 
   // 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.EnableDoublePassIfSuccess = false; 
   options.EnableInvertedSymbols = false; 
   options.EnableFastMode = true; 
   options.EnableSmallSymbols = true; 
   options.EnablePreprocessing = true; 
   options.GS1toHRI = false; 
 
   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} data: {2} and symbology: {3}", barcode.Bounds, barcode.SymbolSize, barcode.Value, barcode.Symbology); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.5.9
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Barcode Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.