您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么用C#生成DataMatrix格式的二維碼”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么用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)其他函數(shù)接口(分別是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、實踐部分:
創(chuàng)建如下界面:按鈕按下,生產(chǎn)條碼。
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"); //以保存特定格式方法生產(chǎn)二維碼 //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(); //調(diào)用其中一個接口,將圖片以bitmap形式顯示出來 } } }
測試結(jié)果:
感謝各位的閱讀,以上就是“怎么用C#生成DataMatrix格式的二維碼”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對怎么用C#生成DataMatrix格式的二維碼這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。