【教程】條形碼組件Spire.Barcode 教程:如何在C#中建立DataMatrix條碼

DataMatrix 條碼是由黑色和白色「單元」組成的二維條形碼,或以正方形或矩形模式排列的模塊。要編碼的信息能夠是文本或數字數據。編碼

代碼:code

Step 1:建立一個BarcodeSettings實例orm

BarcodeSettings settings = new BarcodeSettings();

Step 2:設置條碼模塊的寬度圖片

settings.X = 2;

Step 3:將條碼類型設置爲DataMatrixget

settings.Type = BarCodeType.DataMatrix;

Step 4:設置數據並顯示文字generator

settings.Data = "ABC 123456789ABC 123456789ABC 123456789";
settings.Data2D = "ABC 123456789ABC 123456789ABC 123456789";

Step 5:將DataMatrix符號形狀設置爲正方形angular

settings.DataMatrixSymbolShape = DataMatrixSymbolShape.Square;

Step 6:根據設置生成條形碼圖像並以.png格式保存下載

BarCodeGenerator generator = new BarCodeGenerator(settings);
Image image = generator.GenerateImage();
image.Save("DataMatrix.png", System.Drawing.Imaging.ImageFormat.Png);

圖片1

要建立矩形的DataMatrix條形碼,請將DataMatrixSymbolShape屬性設置爲Rectangle。im

settings.DataMatrixSymbolShape = DataMatrixSymbolShape.Rectangle;

圖片2

完整代碼:數據

BarcodeSettings settings = new BarcodeSettings();
settings.Type = BarCodeType.DataMatrix;
settings.X = 1.5f;
settings.DataMatrixSymbolShape = DataMatrixSymbolShape.Square;
//rectangular DataMatrix barcode
//settings.DataMatrixSymbolShape = DataMatrixSymbolShape.Rectangle;  
settings.Data = "ABC 123456789ABC 123456789ABC 123456789";
settings.Data2D = "ABC 123456789ABC 123456789ABC 123456789";
BarCodeGenerator generator = new BarCodeGenerator(settings);
Image image = generator.GenerateImage();
image.Save("DataMatrix.png", System.Drawing.Imaging.ImageFormat.Png);

點擊下載Spire.Barcode for .NET

相關文章
相關標籤/搜索