Here is the sample Code I have used to
create Data Matrix barcode in C#:
using System;
using System.Collections.Generic;
using System.Text;
using OnBarcode.Barcode;
using System.Drawing.Imaging;
using System.Drawing;
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_16X16;
/*
* 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.
//4 options are: facing left, facing right, facing bottom, and facing top
datamatrix.Rotate = Rotate.Rotate0;
// Generate data matrix and encode barcode to gif format
datamatrix.ImageFormat = System.Drawing.Imaging.ImageFormat.Gif;
datamatrix.drawBarcode("C:\\datamatrix.gif");
/*
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);
*/
The
C# barcode data encoding guide is very helpful.