[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
The DatamatrixBarcodeData class derives from the base BarcodeData to add specific data that can be read or written when using Datamatrix 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.
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:
Dim datamatrixData As DatamatrixBarcodeData = DirectCast(BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.Datamatrix), DatamatrixBarcodeData)
DatamatrixBarcodeData datamatrixData = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.Datamatrix) as DatamatrixBarcodeData;
This example writes a couple of Datamatrix barcodes with different options to an image and then reads them back.
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:\LEADTOOLS21\Resources\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:\LEADTOOLS21\Resources\Images"
End Class
DatamatrixBarcodeReadOptions Class
DatamatrixBarcodeWriteOptions Class
Programming with LEADTOOLS Barcode
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document