C# 如何生成 DataMatrix 格式的二维码

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

  }

  }

  }