您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么用C#生成DataMatrix格式的二維碼”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“怎么用C#生成DataMatrix格式的二維碼”吧!
1、附件為dll
2、利用上述控件生成二維碼的核心代碼:
(a)C#代碼:
DataMatrix datamatrix = new DataMatrix(); datamatrix.Data = "0123456789"; // Create Data Matrix and encode barcode to Jpeg format datamatrix.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; datamatrix.drawBarcode("C://csharp-datamatrix.jpg");
(b)VB.NET代碼:
Dim datamatrix As OnBarcode.Barcode.DataMatrix datamatrix = New OnBarcode.Barcode.DataMatrix() datamatrix.Data = "0123456789" ' Create Data Matrix and encode barcode to Jpeg format datamatrix.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg datamatrix.drawBarcode("C://vbnet-datamatrix.jpg")
(c)其他函數接口(分別是C#和VB):
public void drawBarcode(Graphics graphics); public void drawBarcode(string filename); public Bitmap drawBarcode(); public void drawBarcode(Stream fileStream); Public Sub drawBarcode(ByRef graphics As Graphics) Public Sub drawBarcode(ByVal filename As String) Public Function drawBarcode() As Bitmap Public Sub drawBarcode(ByRef fileStream As Stream)
3、實踐部分:
創建如下界面:按鈕按下,生產條碼。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using OnBarcode.Barcode; using System.Drawing.Imaging; namespace DataMatrix1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { DataMatrix datamatrix = new DataMatrix(); // Barcode data to encode datamatrix.Data = "OnBarcode"; // Data Matrix data mode datamatrix.DataMode = DataMatrixDataMode.ASCII; // Data Matrix format mode datamatrix.FormatMode = DataMatrixFormatMode.Format_10X10; /* * Barcode Image Related Settings */ // Unit of meature for all size related setting in the library. datamatrix.UOM = UnitOfMeasure.PIXEL; // Bar module size (X), default is 3 pixel; datamatrix.X = 3; // Barcode image left, right, top, bottom margins. Defaults are 0. datamatrix.LeftMargin = 0; datamatrix.RightMargin = 0; datamatrix.TopMargin = 0; datamatrix.BottomMargin = 0; // Image resolution in dpi, default is 72 dpi. datamatrix.Resolution = 72; // Created barcode orientation. // Rotate0 = 0, // Rotate90 = 1, // Rotate180 = 2, // Rotate270 = 3, // 4 options are: facing left, facing right, facing bottom, and facing top datamatrix.Rotate = Rotate.Rotate0; // Geneat data matrix and encode barcode to gif format datamatrix.ImageFormat = System.Drawing.Imaging.ImageFormat.Bmp; datamatrix.drawBarcode("C:\\datamatrix.jpg"); //以保存特定格式方法生產二維碼 //You can also call other drawing methods to generate barcodes //public void drawBarcode(Graphics graphics); //public void drawBarcode(string filename); //public Bitmap drawBarcode(); //public void drawBarcode(Stream stream); //將該種編碼的格式,寫入文件流之中 this.pictureBox1.Image = datamatrix.drawBarcode(); //調用其中一個接口,將圖片以bitmap形式顯示出來 } } }
測試結果:
感謝各位的閱讀,以上就是“怎么用C#生成DataMatrix格式的二維碼”的內容了,經過本文的學習后,相信大家對怎么用C#生成DataMatrix格式的二維碼這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。