Data Matrix Generator Library for .NET in C# Class
How to Generate 2D Data Matrix Barcodes in .NET with C# Programming
100% built in Visual C#, compatible with .NET Framwork 2.0, 3.0, 3.5, 4.0 and later
Run perfectly in many .NET Framework applications, like WinForms and ASP.NET
Create high-quality Data Matrix barcode images with C# codes in .NET
Insert & draw Data Matrix barcodes in Crystal Reports and RDLC Reports
Save generated Data Matrix barcodes as image files without using barcode fonts
Suitable for other linear & 2D barcodes generation, like EAN13, Code 128, QR Code, etc
Data Matrix Introduction
Data Matrix is a 2 dimensional (2D) matrix barcode symbology, with high-density data and strong error correction ability. It has two types-ECC 200 and ECC000-140. In the real daily life, ECC200 is more widely used.
Quick to Create Data Matrix 2D Barcodes using C#
Create a new DataMatrix object
Enter Data Matrix encoding text in property Data
Use method drawBarcode() to generate, print Data Matrix barcode to a PNG image file
Data Matrix 2d barcode supports the following character set, data encoding using C#.
Full 128 ASCII table chars
Unicode text
GS1 Data Matrix
Encode Data Matrix ASCII characters
Full 128 ASCII (American Standard Code for Information Interchange) table includes 95 printable characters (such as Uppercase, Lowercase letters, digits),
and 33 control characters (such as char 'carriage return'), which are not printable.
Creating Data Matrix with printable ASCII chars encoded is really easy. You can directly enter the ASCII chars to property Data.
To create Data Matrix with ASCII control chars (non-printing chars), you need convert each control char to it's ASCII interger value in three digits string, then pass to the property Data
provide control char's ASCII integer value to property Data
Enable property ProcessTilde to true. The C# barcode library will process all 3-digit string following tilde "~".
In property Data, all control chars will be converted to it's ASCII integer value in 3-digit string behind char ~, and they will be inserted to the Data Matrix encoding code
Set property IsUnicodeData to true. The C# Data Matrix Generator library will automatically encode the Unicode text in the property Data to Data Matrix barcode in C# application.
DataMatrixbarcode=newDataMatrix();
barcode.Data="你好"; // hello in Chinesebarcode.IsUnicodeData=true;
barcode.drawBarcode("C://BarcodeLib//csharp-data-matrix-unicode-text.png");
Encode GS1 Data Matrix Barcodes
Set property FNC1Mode to DataMatrixFNC1Mode.FirstPosition. The barcode generation library will encode and print GS1 Data Matrix in C# application.
Data Matrix barcodes usually are in square shapes. To create square Data Matrix, you need only set the barcode image width in property ImageWidth.
The C# source code below will generate Data Matrix with width in 250 pixels, and height in 250 pixels.
Here we will learn how to create and customize Data Matrix 2d barcode bar/space module colors, image padding area colors and image settings using C# Barcode Generator library.
Color options
The BarcodeLib C# Barcode Library allows you to generate and customize colors for Data Matrix barcode modules in C# ASP.NET web applications and desktop projects.
You can independently set colors for barcode bars and blank spaces.
Create a new DataMatrix object and assign the data text "Data Matrix".
Set the ModuleColor property to define the color of Data Matrix bar modules (use red).
Set the BackgroundColor property to define the color of Data Matrix space modules (use light blue).
Call the drawBarcode() method to generate and export the Data Matrix as a PNG image file.
Notes:
Maintain strong color contrast between Data Matrix bar module color and background color to ensure successful scanning.
Do not use similar or low-contrast color combinations, as they will make the barcode unreadable.
Data Matrix image padding area color
When you create Data Matrix images, you may notice extra blank space appearing around the Data Matrix barcode.
This extra padding is a common display effect for 2d barcodes, including QR Code, Data Matrix and PDF417.
You can eliminate the visual impact of this extra space by setting its color to transparent.
Set ResizeImagePaddingTransparent to false to display the padding area around the Data Matrix bar and space modules.
By default, the property is set to true. The Data Matrix image below is generated with the ResizeImagePaddingTransparent property set to false.
This image shows the visible extra space effect for reference.
Ensure your output image format (such as PNG) supports transparency before enabling this setting.
Image formats like JPG and BMP do not support transparency and will not display the transparent effect correctly.
Verify the final barcode display after configuration to ensure no unwanted padding is visible.
High resolution Data Matrix image
When creating a Data Matrix image for printing, it's critical to ensure the Data Matrix image resolution is higher than your printer's resolution.
This ensures the printed barcode is clear, sharp, and scannable.
To generate a high-resolution Data Matrix image, you only need to configure one properties using the C# barcode library.
Resolution
Set the resolution value to a number that is larger than your printer's horizontal and vertical resolutions. This ensures the Data Matrix retains clarity when printed, even at larger sizes.
barcode.Resolution=900;
Note:
Always check your printer's resolution first before setting the Data Matrix barcode's Resolution property.
Using a resolution lower than the printer's resolution will result in blurry, unreadable printed barcodes.
Avoid GIF format entirely for high-resolution printing purposes. Use PNG, JPG, or BMP.
Test the printed barcode after configuration to confirm it is scannable and clear.
Output Data Matrix to raster, vector image formats
BarcodeLib C# Barcode library supports printing Data Matrix to various raster and vector image formats.
DataMatrixEncoding.Base256. Encoding All byte values 0 - 255.
Using BarcodeLib C# Data Matrix Barcode Generator library, we strongly recommend you to choose DataMatrixEncoding.Auto (default value) for
property Encoding. With auto mode, the barcode library will automatically analyze the Data Matrix encoding text and select the suitable combination of the six encoding modes in C# application.
Data Matrix ISO standard specifies 24 square symbols and 6 rectangular symbols available in ECC 200.
Each symbol size includes different rows and columns with different data storage capacity.
Using BarcodeLib C# Barcode library, you can specify the Data Matrix format mode using property FormatMode.
If your encoding Data Matrix data size is larger than your specified Data Matrix format mode, the barcode library will automatically choose the right format mode for you.
Data Matrix barcode ISO standard provides a mechanism for the data in a file to be split into blocks and be represented in multiple Data Matrix barcode symbols.
Set property EnableStructuredAppend to true to enable Data Matrix Structured Append mode
Set property StructuredAppendCount to specify the total number of Data Matrix barcode symbols to store the same data message
Set property StructuredAppendIndex to specify the order of the current data matrix. The first symbol index should be 0. The C# sample code below will create the first Data Matrix symbol.
Set property StructuredAppendFileID with a random unique integer.
All data matrix barcodes to store the same data message should have the same StructuredAppendFileID value.
DataMatrixbarcode=newDataMatrix();
barcode.Data="Data Matrix";
barcode.EnableStructuredAppend=true;
// The whole data message will be stored in three Data Matrix barcodesbarcode.StructuredAppendCount=3;
// This Data Matrix symbol is the first onebarcode.StructuredAppendIndex=0;
// All three Data Matrix barcodes must have the same file idbarcode.StructuredAppendFileID=999;
barcode.drawBarcode("C://BarcodeLib//csharp-data-matrix-structured-append.png");
How to Create Data Matrix in C# ASP.NET web app?
Our C# Data Matrix Barcodes Generator Library also allows users to generate Data Matrix in ASP.NET Web Project. The following are detailed steps:
Add Barcodelib.Barcode.ASP.NET.dll to your web project.
Add Barcodelib.Barcode.ASP.NET.dll to the Toolbox.
Copy files "datamatrix.aspx" & "datamatrix.aspx.cs" from the folder barcode in the downloaded trial package to the folder where your web project is located.
Drag DataMatrixASPNET from the toolbox to the split part of your aspx page, and then change its settings in the Properties window or with above C# source code.
How to Generate Data Matrix in C# WinForms?
You may use our C# Generator DLL to create a Data Matrix image in WinForms Project with following steps:
Add BarcodeLib.Barcode.WinForms.dll from the downloaded trial package to your WinForms Project.
Add BarcodeLib.Barcode.WinForms.dll to your Visual Studio Toolbox.
Drag DataMatrixWinForm to your windows form and a Data Matrix barcode will be produced or you could use above free C# source code to create Data Matrix.