该文主要是利用OnBarcode.dll 生成 DataMatrix 格式的二维码的一些简单方法和操作技巧。关于QrBarcode的二维码比较常见和简单,网上有很多资源。

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形式显示出来

}

}

}

测试结果:

当初只是随便分享一下,没想到大家使用条码的这么多,评论也有很多,谢谢大家支持。

这里附上几个条码常用的dll。

可在这里下载:https://i.cnblogs.com/Files.aspx

事实上:生成条码的方法有很多种,库也有很多,大家可以多去琢磨琢磨,不能局限一种,就我所知所用过的就有五个库。

网上也有很多对条码底层的开源研究,可自行。

分享共进步,谢谢阅读!

C# 生成 DataMatrix 格式的二维码的更多相关文章

  1. .NET使用ZXing.NET生成中间带图片的二维码

    很久之前就有写这样的代码了,只是一直没记录下来,偶然想写成博客. 把之前的代码封装成函数,以方便理解以及调用. 基于开源的 ZXing.NET 组件,代码如下: 先添加对ZXing.NET的引用,然后 ...

  2. C# ZXing.Net生成二维码、识别二维码、生成带Logo的二维码(二)

    1.使用ZXint.Net生成带logo的二维码 /// <summary> /// 生成带Logo的二维码 /// </summary> /// <param name ...

  3. 微信公众号生成带参数的二维码asp源码下载

    晚上闲着没事,一个朋友联系,让帮忙写一个微信公众号利用asp生成带参数的二维码,别人扫了后如果已经关注过该公众号的,则直接进入公众号里,如果没关注则提示关注,关注后自动把该微信用户资料获取到并且保存入 ...

  4. C#生成带logo的二维码

    带logo的二维码生成分为两步骤:首先根据输入的内容生成二维码图片,然后读取本地的logo图片,通过图片处理生成带logo的二维码. 生成的二维码效果如下: 下面直接贴出二维码生成类   QRCode ...

  5. js生成带参的二维码

    最近项目中有需求生成带参的二维码,考虑过用JAVA后台生成返回前端展示,后面了解到用jquery的qrcode.js插件可以很好现实 引入js: require.config({ baseUrl : ...

  6. .NET生成带Logo的二维码

    使用ThoughtWorks.QRCode生成,利用这个库来生成带Logo的二维码(就是中间嵌了一个图片的二维码),直接见代码: HttpContext context = HttpContext.C ...

  7. C#+ZXing.dll生成手机路径导航二维码

    1.原谅我先写点废话哈 这两天用C#写一个C端的软件,甲方提出一个很无理的需求(在C端的程序中实现路径导航,关键是这个程序最终是运行在物理隔绝的电脑上的……),头疼了好几天,领导突然想到可以把坐标+百 ...

  8. js实现生成中间带图片的二维码

    之前需要实现生成中间带图片的二维码,所以找了半天终于找到一个可以用的.于是在这里记录一下. 下面是需要注意的几点: 1.使用的js为jquery-qrcode 但是已经经过别人的修改,和网上原来的那些 ...

  9. PHP生成有背景的二维码图,摘自网络

    有一天产品MM高高兴兴的走过来,兴奋的和我分享她想出来的一个新的idea. 产品MM:你看这个(她指了指她的手机),一脸兴奋 那是一张带着二维码的图片,内容如下: 她接着说:如果我们的分销也能做成类似 ...

随机推荐

  1. c3p0、dbcp、proxool、BoneCP比较

    1.1 测试环境: 操作系统:windows xp sp3 数据库:mysql 5.1 1.2 测试条件: initialSize=30; maxSize=200; minSize=30; 其余参数为 ...

  2. dwz 刷新当前navtab

    List.jsp 其navtabId为TradingStrategy_31: <form method="post" action="${contextPath}/ ...

  3. “==”和equals之间的区别

    通俗点讲,==是看看左右是不是一个东西.equals是看看左右是不是长得一样.如果单纯是想记住,==:等于.equals:相同.两个长得一样的人,只能说长的相同(equals),但是不等于他们俩是一个 ...

  4. codeforces 560 C Gerald&#39;s Hexagon

    神精度--------这都能过.随便算就好了,根本不用操心 就是把六边形补全成三角形.然后去掉补的三个三角形,然后面积除以边长1的三角形的面积就可以.... #include<map> # ...

  5. [14] 齿轮(Gear Wheel)图形的生成算法

    顶点数据的生成 bool YfBuildGearwheelVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices ...

  6. 原创BULLET物理的DEMO

    原创BULLET物理的DEMO 按空格和0,1,2,3,4,5,6会发射不同的刚体. 具体的使用说明: 鼠标右键按下并拖动         旋转视角WSAD                       ...

  7. kth-smallest-element-in-a-sorted-matrix

    //有很多讨论,比如 // https://discuss.leetcode.com/topic/52865/my-solution-using-binary-search-in-c // https ...

  8. UVA 400 (13.08.05)

     Unix ls  The computer company you work for is introducing a brand new computer line and is developi ...

  9. Python操作Excel表格,xlwt模块的使用

    Python可以操作Excel的模块不止一种,我习惯使用的写入模块是xlwt(一般都是读写模块分开的) 按照模块使用pip install xlwt 就行了,很常规的方式 直接进代码解析,本文源码 w ...

  10. 【转】NativeScript的工作原理:用JavaScript调用原生API实现跨平台

    原文:https://blog.csdn.net/qq_21298703/article/details/44982547 -------------------------------------- ...