该文主要是利用OnBarcode.dll 生成DataMatrix 格式的二维码的一些简单方法和操作技巧。关于QrBarcode的二维码比较常见和简单,网上有很多资源。
1、附件为dll
2、利用上述控件生成二维码的核心代码:
(a)C#代码:
1
2
3
4
5
6
|
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代码:
1
2
3
4
5
6
7
|
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):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
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、实践部分:
创建如下界面:按钮按下,生产条码。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
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形式显示出来 } } } |
测试结果:
当初只是随便分享一下,没想到大家使用条码的这么多,评论也有很多,谢谢大家支持。
这里附上几个条码常用的dll。
可在这里下载:https://i.cnblogs.com/Files.aspx
事实上:生成条码的方法有很多种,库也有很多,大家可以多去琢磨琢磨,不能局限一种,就我所知所用过的就有五个库。
网上也有很多对条码底层的开源研究,可自行。
到此这篇关于C# 如何生成 DataMatrix 格式的二维码的文章就介绍到这了,更多相关C# DataMatrix 格式二维码内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://www.cnblogs.com/imyao/p/5616237.html