Data Matrix Barcode Dimension Size in C#
Quick to create data matrix with specified width in C#
- Create a new DataMatrix object with data encoding
- Set property BarcodeWidth to 900 pixels. You will get a data matrix image with 900 pixels in width and 900 pixels in height.s
DataMatrix barcode = new DataMatrix();
barcode.Data = "Data Matrix";
barcode.BarcodeWidth = 900; // 900 pixels or points
barcode.drawBarcode("C://Output//csharp-datamatrix-size.png");
Generate rectangular Data Matrix with specified width and height using C#
Data Matrix (ECC200) has specified 6 rectangular symbols. Using C# barcode library, you can create these barcodes through property
FormatMode
- 8 rows x 18 columns
- 8 rows x 32 columns
- 12 rows x 26 columns
- 12 rows x 36 columns
- 16 rows x 36 columns
- 16 rows x 48 columns
To create a rectangular Data Matrix with your specified width and height, you need provide the same image width vs height ratio with Data Matrix columns vs rows ratio.
- Initialize a DataMatrix object in C# class
- Set the encode data in "Data" property
- Specify the rectangular format mode. Here we will create a rectangular Data Matrix in 16 rows and 48 columsn.
- Set the specified image width and height
- Call drawBarcode() to generate and print rectangular Data Matrix to an image file
DataMatrix barcode = new DataMatrix();
barcode.Data = "Data Matrix";
barcode.FormatMode = DataMatrixFormatMode.Format_16X48;
barcode.BarcodeWidth = 900;
barcode.BarcodeHeight = 300;
barcode.drawBarcode("C://Output//csharp-datamatrix-size-rectangular.png");
Advanced Data Matrix dimension width & height settings in C#
The width of a Data Matrix barcode, including quiet zones, can be calculated from the following expression:
W = Row * X + 2Q
where
Note: if the Data Matrix is a square, the width and height are the same value.
In C# data matrix barcode generator, you can use the following barcode dimension size settings:
- UOM: Unit of measure. You can choose PIXEL, CM or INCH.
- X: Width of the bar module. The mimumum bar width is defined by the application specification
- FormatMode: Data Matrix symbol size format mode.
- LeftMargin, RightMargin, TopMargin, BottomMargin: Quiet zone. the minimum width of quiet zone is X.
C# source code to set Data Matrix barcode image size.
DataMatrix barcode = new DataMatrix();
barcode.Data = "Data Matrix";
barcode.DataMode = DataMatrixDataMode.Auto;
// Select symbol size format mode
barcode.FormatMode = DataMatrixFormatMode.Format_20X20;
// Barcode Size Related Settings
barcode.AutoResize = false;
barcode.UOM = UnitOfMeasure.PIXEL;
barcode.X = 5;
barcode.LeftMargin = 5;
barcode.RightMargin = 5;
barcode.TopMargin = 5;
barcode.BottomMargin = 5;
barcode.Resolution = 96;
// Image format setting
barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
barcode.drawBarcode("W://Projects//csharp-data-matrix-symbol-size.png");
Each symbol size format mode has
its' maxium data capacity.
If your encoding data exceeds its maximum data capacity, the barcode
generator library will choose the best data format mode for you.
Data Matrix Color and Image Option Settings using C#
Colors in Data Matrix
By default the Data Matrix modules color should be dark and the background color should be light. Sometimes the Data Matrix symbols will
also be printed to appear as light on dark.
The left image below is a standard Data Matrix with dark on light. And the right one is also a valid Data Matrix with light on dark.
The following C# source code will generate 3 Data Matrix images with the same encoding data, and different bar, space colors.
- A standard Data Matrix: bar color is black, and space color is white.
- A standard Data Matrix also: bar color is white, and space color is black.
- A Data Matrix: bar color is red, and space color is white. It is not a standard Data Matrix, you need make sure the barcode scanners support it.
{
DataMatrix barcode = new DataMatrix();
barcode.Data = "A1B2C3D4E5F6G7H8I9J0K1L2";
barcode.drawBarcode("C://Output//csharp-datamatrix-dark-on-light.png");
}
{
DataMatrix barcode = new DataMatrix();
barcode.Data = "A1B2C3D4E5F6G7H8I9J0K1L2";
barcode.ForeColor = Color.White;
barcode.BackColor = Color.Black;
barcode.drawBarcode("C://Output//csharp-datamatrix-light-on-dkar.png");
}
{
DataMatrix barcode = new DataMatrix();
barcode.Data = "A1B2C3D4E5F6G7H8I9J0K1L2";
barcode.ForeColor = Color.Red;
barcode.drawBarcode("C://Output//csharp-datamatrix-colors.png");
}
You can also find more about color settings in barcode, such as transparent background barcodes here:
How to customize barcode colors using C# barcode library?
Image Settings in Data Matrix
To create Data Matrix in raster image format, you can specify the image format through property
System.Drawing.Imaging.ImageFormat.
And you can also directly output Data Matrix barcode into vector image format (SVG and EPS) through drawing method
drawBarcode2SVG() and
drawBarcode2EPS().
{
DataMatrix barcode = new DataMatrix();
barcode.Data = "A1B2C3D4E5F6G7H8I9J0K1L2";
barcode.ImageFormat = ImageFormat.Jpeg;
barcode.drawBarcode("C://Output//csharp-datamatrix-image-jpeg.jpg");
}
{
DataMatrix barcode = new DataMatrix();
barcode.Data = "A1B2C3D4E5F6G7H8I9J0K1L2";
barcode.drawBarcode2SVG("C://Output//csharp-datamatrix-image-svg.svg");
}
{
DataMatrix barcode = new DataMatrix();
barcode.Data = "A1B2C3D4E5F6G7H8I9J0K1L2";
barcode.drawBarcode2EPS("C://Output//csharp-datamatrix-image-eps.eps");
}
You can also get more image settings such as high resolution barcodes here:
How to customize barcode images using C# barcode generator library?
What is a data matrix code?
A data matrix code is a 2-dimensional code that is made of black and white cells that are usually arranged in a square pattern.
Using C# barcode generator library, you can easily generate, customize and print Data Matrix barcodes in OnBarcode.Barcode.DataMatrix class in C# codes.
What is the ISO standard for Data Matrix?
Data Matrix ISO specification is ISO/IEC 16022, and the latest standard version is ISO/IEC 16022:2024.
C# Barcode Generator library fully support ISO compatible Data Matrix generations in C# applications.
What are the different types of Data Matrix?
According to Data Matrix latest ISO specification, there are two versions of Data Matrix
- ECC 000-140
- ECC 200. OnBarcode C# barcode library fully support Data Matrix ECC200, which uses the Reed-Solomon error correction.
How much data can a Data Matrix store?
It depends on the Data Matrix encoding data formats.
- Alphanumeric data: up to 2,335 characters
- Byte data (8-bit): 1,555 characters
- Numeric data: 3,116 digits
If your encoding text size is over the maximum Data Matrix capacity, the barcode library will through an exception or create an empty image with error message in C# apps.
What is the minimum and maximum size of Data Matrix barcode?
The minimum size of Data Matrix is 10 x 10 modules. And the maximum size of Data Matrix is 144 x 144 modules.
OnBarcode C# Barcode library supports all formats defined in Data Matrix ISO standard. You can customize the Data Matrix format through
DataMatrixFormatMode using C#.
Can a phone scan a Data Matrix?
Yes. You can scan a Data Matrix using your iPhone with your 3rd party app installed.
Is a Data Matrix the same as a QR Code?
No. They are not the same barcode symbologies. Data Matrix and QR Code have lot of same features. They are both 2d barcodes, and enable to encode ASCII text, Unicode text, binary data.
Both of them are encoding GS1 business data messages.
C# Barcode Generator SDK fully supports both Data Matrix and QR Code generations in C# ASP.NET, MVC, Windows Forms, WPF, C# console applications.
OnBarcode C# Barcode Generator makes it easy to generate, create Data Matrix and other linear & 2d barcodes in Microsoft Word.
OnBarcode provides several Data Matrix Generator components and software, including
Data Matrix VB.NET,
Data Matrix ASP.NET,
Data Matrix Java,
Data Matrix for BIRT reports,
Data Matrix for Excel,
Data Matrix Generator.
This document is providing a detailed C# source code about generating Data Matrix barcodes in C# class using
C# Barcode generation component.