DataMatrix是二维的条形码,它是由黑色和白色的单元格构成,这些单元格分布于一个正方形或者矩形的模型中。它可以存储文本信息和数字信息。
下面的例子将展示如何用Spire.Barcode for .NET生成一个DataMatrix条形码。
C#
//生成BarcodeSettings实例
BarcodeSettings settings = new BarcodeSettings();
//设置条形码类型为DataMatrix
settings.Type = BarCodeType.DataMatrix;
//设置条形码模型宽度
settings.X = 1.5f;
//设置DataMatrix模型为正方形
settings.DataMatrixSymbolShape = DataMatrixSymbolShape.Square;
//设置DataMatrix模型为矩形
//settings.DataMatrixSymbolShape = DataMatrixSymbolShape.Rectangle;
//设置数据和显示文本
settings.Data = "ABC 123456789ABC 123456789ABC 123456789";
settings.Data2D = "ABC 123456789ABC 123456789ABC 123456789";
//生成DataMatrix条形码并保存为png格式的图片
BarCodeGenerator generator = new BarCodeGenerator(settings);
Image image = generator.GenerateImage();
image.Save("DataMatrix.png", System.Drawing.Imaging.ImageFormat.Png);
VB.NET
'生成BarcodeSettings实例
Dim settings As New BarcodeSettings()
'设置条形码类型为DataMatrix
settings.Type = BarCodeType.DataMatrix
'设置条形码模型宽度
settings.X = 1.5F
'设置DataMatrix模型为正方形
settings.DataMatrixSymbolShape = DataMatrixSymbolShape.Square
'设置DataMatrix模型为矩形
'settings.DataMatrixSymbolShape = DataMatrixSymbolShape.Rectangle;
'设置数据和显示文本
settings.Data = "ABC 123456789ABC 123456789ABC 123456789"
settings.Data2D = "ABC 123456789ABC 123456789ABC 123456789"
'生成DataMatrix条形码并保存为png格式的图片
Dim generator As New BarCodeGenerator(settings)
Dim image As Image = generator.GenerateImage()
image.Save("DataMatrix.png", System.Drawing.Imaging.ImageFormat.Png)
正方形:
矩形: