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);
要建立矩形的DataMatrix條形碼,請將DataMatrixSymbolShape屬性設置爲Rectangle。im
settings.DataMatrixSymbolShape = DataMatrixSymbolShape.Rectangle;
完整代碼:數據
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);