C# Data Matrix Reader Library
How to read, scan 2D Data Matrix barcode images using C#.NET
Data Matrix barcode reading from documents and image files Using C#. Support read barcode from PDF, Tiff, Jpeg, Word files.
In this C# tutorial, you will learn how to read, recognize Data Matrix 2d barcode from PDF, Tiff and image files in your C# asp.net, Windows apps.
- Easy to read, scan Data Matrix barcodes from image, PDF files
- Reading Data Matrix from PDF, Tiff and PNG, JPG, Bitmap image files
- Advanced scanning options to speed up reading
How to scan, read Data Matrix from PDF, Tiff, image files using C#
- Decode Data Matrix barcode from documents file like PDF, Word, Excel and PowerPoint using C#
- Recognize Data Matrix from scanned raster image file, like png, gif & bmp using C#
- Read all Data Matrix barcodes from target document image file quickly in C#.NET
- Scan Data Matrix barcode from whole page or any defined rectangular area using C#
- Free to set the number of Data Matrix needed to be recognized from source file
- Return & output scanned Data Matrix values to data string in C#.NET class application
- Support other linear & 2d barcode recognition from document image file using C# code
About Data Matrix barcode
Data Matrix is a commonly-used 2D barcode type. It consists of black & white modules which are grouped in a square or rectangular pattern. Similar to other 2d barcodes, Data Matrix barcode can store huge information with a small printout barcode size. Besides, Data Matrix also owns strong error correction levels, which makes Data Matrix barcode readable even when the barcode damage has been up to 60%.
There are many factors that affect the recognition & reading of Data Matrix barcode from document image file in .NET class application, like quiet zone width of Data Matrix and resolution of generated Data Matrix barcode image. Besides barcode reading functions, RasterEdge DocImage SDK for .NET also supports fast Data Matrix barcode generation in VB.NET class application.
Sample C# source code for Data Matrix barcode reading from PDF document
If you want to read & recognize Data Matrix barcode from scanned PDF document file in C#.NET class application, this barcode reader control will be a great choice. With one line of code, you can detect and decode all the Data Matrix barcodes existing on the target PDF document file. Besides, with the application of X & Y location, you are allowed to define the Data Matrix barcode scanning area.
public static void ReadDataMatrixBarcodeFromPDF()
{
String inputFilePath = @"C:\1.pdf";
// Open PDF file
PDFDocument doc = new PDFDocument(inputFilePath);
// Initial reader's setting
ReaderSettings settings = new ReaderSettings();
// Set target barcode type
settings.AddTypesToRead(BarcodeType.DataMatrix);
// Scan barcodes from the document.
Barcode[] result = BarcodeReader.ReadBarcodes(settings, doc);
if (result.Length > 0)
{
foreach (Barcode barcode in result)
Console.WriteLine("Barcode Data: " + barcode.DataString);
}
else
Console.WriteLine("[No Barcode Found]");
}
Sample C# source code for reading Data Matrix from TIFF image file
With RasterEdge .NET Barcode Reader SDK, users are allowed to reading Date Matrix not only from png, jpeg, bmp and gif image files, but also tiff images.
This is the C# demo code for reading Date Matrix from tiff.
public static void ReadDataMatrixBarcodeFromTiff()
{
String inputFilePath = @"C:\1.tif";
// Open TIFF file
TIFFDocument doc = new TIFFDocument(inputFilePath);
// Initial reader's setting
ReaderSettings settings = new ReaderSettings();
// Set target barcode type
settings.AddTypesToRead(BarcodeType.DataMatrix);
// Scan barcodes from the document.
Barcode[] result = BarcodeReader.ReadBarcodes(settings, doc);
if (result.Length > 0)
{
foreach (Barcode barcode in result)
Console.WriteLine("Barcode Data: " + barcode.DataString);
}
else
Console.WriteLine("[No Barcode Found]");
}
Sample C# source codes to decode Data Matrix from JPEG image file
This C#.NET barcode scanning control supports reading & decoding one or more 2D Data Matrix barcode(s) from several commonly-used raster image file formats, including png, jpeg, bmp, tiff and gif. Using the sample C# code below, you can easily detect & decode all Data Matrix barcodes from png image files in .NET class application.
public static void ReadDataMatrixBarcodeFromJpeg()
{
String inputFilePath = @"C:\1.jpg";
// Open JPEG file
Bitmap bitmap = new Bitmap(inputFilePath);
// Initial reader's setting
ReaderSettings settings = new ReaderSettings();
// Set target barcode type
settings.AddTypesToRead(BarcodeType.DataMatrix);
// Scan barcodes from the document.
Barcode[] result = BarcodeReader.ReadBarcodes(settings, bitmap);
if (result.Length > 0)
{
foreach (Barcode barcode in result)
Console.WriteLine("Barcode Data: " + barcode.DataString);
}
else
Console.WriteLine("[No Barcode Found]");
}
C#: scan, read Data Matrix barcode data from stream objects using C#
Using barcode reader SDK, you can not only read 2d data matrix from image document files, you can also scan, read data matrix barcode data from stream objects directly using C#.
public static void ReadDataMatrixBarcodeFromBitmapStream()
{
String inputFilePath = @"C:\1.png";
using (FileStream fs = File.Open(inputFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
// Open PNG stream
Bitmap bitmap = new Bitmap(fs);
// Initial reader's setting
ReaderSettings settings = new ReaderSettings();
// Set target barcode type
settings.AddTypesToRead(BarcodeType.DataMatrix);
// Scan barcodes from the document.
Barcode[] result = BarcodeReader.ReadBarcodes(settings, bitmap);
if (result.Length > 0)
{
foreach (Barcode barcode in result)
Console.WriteLine("Barcode Data: " + barcode.DataString);
}
else
Console.WriteLine("[No Barcode Found]");
}
}
Sample C# source code to read, recognize Data Matrix barcodes from Microsoft Word document in .NET
Data Matrix barcode reading from Word works in the same way with that from PDF document. You can also detect and recognize all the Data Matrix barcodes from target Word page within a single line of code and return the decoded barcode values to data string. Similarly, if the Data Matrix barcode(s) needed to be decoded is located in a fixed area, you can use X & Y location to set the barcode scanning area using C# code.
public static void ReadDataMatrixBarcodeFromWord()
{
String inputFilePath = @"C:\1.docx";
// Open .docx file
DOCXDocument doc = new DOCXDocument(inputFilePath);
// Initial reader's setting
ReaderSettings settings = new ReaderSettings();
// Set target barcode type
settings.AddTypesToRead(BarcodeType.DataMatrix);
// Scan barcodes from the document.
Barcode[] result = BarcodeReader.ReadBarcodes(settings, doc);
if (result.Length > 0)
{
foreach (Barcode barcode in result)
Console.WriteLine("Barcode Data: " + barcode.DataString);
}
else
Console.WriteLine("[No Barcode Found]");
}
More advanced features to read Data Matrix barcodes
To improve the Data Matrix reading speed, you can scan and read Data Matrix data from image region area, PDF, Tiff pages list. The following demo codes will show how to do it.
C#: scan, read Data Matrix barcodes with multiple barcode types using C#
The C# code below will scan, read multiple barcode types from an image file.
public static void ReadDataMatrixBarcodeWithMultipleTypes()
{
String inputFilePath = @"C:\1.jpg";
// Open JPEG file
Bitmap bitmap = new Bitmap(inputFilePath);
// Initial reader's setting
ReaderSettings settings = new ReaderSettings();
// Set multiple target barcode types to Code128, DataMatrix and QRCode
settings.AddTypesToRead(BarcodeType.Code128);
settings.AddTypesToRead(BarcodeType.DataMatrix);
settings.AddTypesToRead(BarcodeType.QRCode);
// Scan barcodes from the document.
Barcode[] result = BarcodeReader.ReadBarcodes(settings, bitmap);
if (result.Length > 0)
{
foreach (Barcode barcode in result)
{
Console.WriteLine("Barcode Type: " + barcode.Type.ToString());
Console.WriteLine("Barcode Data: " + barcode.DataString);
}
}
else
Console.WriteLine("[No Barcode Found]");
}
The following c# source code will scan, read all sdk supported barcode types from the document.
public static void ReadDataMatrixBarcodeWithAllTypesSupported()
{
String inputFilePath = @"C:\1.jpg";
// Open JPEG file
Bitmap bitmap = new Bitmap(inputFilePath);
// Initial reader's setting
ReaderSettings settings = new ReaderSettings();
// Set target barcode types to All.
settings.AddTypesToRead(BarcodeType.All);
// Scan barcodes from the document.
Barcode[] result = BarcodeReader.ReadBarcodes(settings, bitmap);
if (result.Length > 0)
{
foreach (Barcode barcode in result)
{
Console.WriteLine("Barcode Type: " + barcode.Type.ToString());
Console.WriteLine("Barcode Data: " + barcode.DataString);
}
}
else
Console.WriteLine("[No Barcode Found]");
}
C#: scan, read, decode 2d Data Matrix barcodes from a specified image region
The C# code below will scan, read Data Matrix barcode datas from an image region.
public static void ReadDataMatrixBarcodeFromImageRegion()
{
String inputFilePath = @"C:\1.jpg";
// Open JPEG file
Bitmap bitmap = new Bitmap(inputFilePath);
// Initial reader's setting
ReaderSettings settings = new ReaderSettings();
// Set target barcode type
settings.AddTypesToRead(BarcodeType.DataMatrix);
// Set scan region: from 10% to 50% of width in horizontal (from left to right)
// and from 0% to 40% of height in vertical (from top to bottom).
settings.RegionOfInterest = new Rectangle(10, 0, 50, 40);
// Scan barcodes from the document.
Barcode[] result = BarcodeReader.ReadBarcodes(settings, bitmap);
if (result.Length > 0)
{
foreach (Barcode barcode in result)
Console.WriteLine("Barcode Data: " + barcode.DataString);
}
else
Console.WriteLine("[No Barcode Found]");
}
C#: scan, read barcode Data Matrix from PDF page list
The C# code below will scan, read Data Matrix datas from Adobe PDF document pages list
public static void ReadDataMatrixBarcodeFromPDFPagesList()
{
String inputFilePath = @"C:\1.pdf";
// Open PDF file
PDFDocument doc = new PDFDocument(inputFilePath);
// Initial reader's setting
ReaderSettings settings = new ReaderSettings();
// Set target barcode type
settings.AddTypesToRead(BarcodeType.DataMatrix);
// Scan barcodes from the first page.
int pageIndex = 0;
Barcode[] result = BarcodeReader.ReadBarcodes(settings, doc.GetPage(pageIndex));
if (result.Length > 0)
{
foreach (Barcode barcode in result)
Console.WriteLine("Barcode Data: " + barcode.DataString);
}
else
Console.WriteLine("[No Barcode Found]");
}
C#: scan, read barcode Data Matrix from tiff document pages list
The C# code below will scan, read Data Matrix datas from tiff document pages list
public static void ReadDataMatrixBarcodeFromTiffPagesList()
{
String inputFilePath = @"C:\1.tif";
// Open TIFF file
TIFFDocument doc = new TIFFDocument(inputFilePath);
// Initial reader's setting
ReaderSettings settings = new ReaderSettings();
// Set target barcode type
settings.AddTypesToRead(BarcodeType.DataMatrix);
// Scan barcodes from the first page.
int pageIndex = 0;
Barcode[] result = BarcodeReader.ReadBarcodes(settings, doc.GetPage(pageIndex));
if (result.Length > 0)
{
foreach (Barcode barcode in result)
Console.WriteLine("Barcode Data: " + barcode.DataString);
}
else
Console.WriteLine("[No Barcode Found]");
}
Common Asked Questions
A Data Matrix is a 2D barcode composed of black and white cells, that stores information as a grid of dark and light squares, typically in a square shape. Using RasterEdge XImage.Barcode Reader C# library, you can
scan, read and decode data matrix code from image files, PDF, tiff, Office Word, Excel, PowerPoint documents in
Visual Studio ASP.NET, Windows Forms applications.
What ISO standard applies to Data Matrix?
The ISO/IEC standard for Data Matrix is 16022, with the latest version being ISO/IEC 16022:2024.
RasterEdge develops both ISO standard compatible Data Matrix Generator and Reader C# library for .NET developers
to enable Data Matrix 2d barcode reading and creating functions in Visual Studio .NET projects.
Can you scan a Data Matrix with a phone?
Yes. You can scan and decode Data Matrix codes from images using a barcode scanner app on your iPhone or Android smartphone.
Using C# Scanner and Reader library, you can use Visual Studio to create and build mobile phone apps to decode Data Matrix on smart phones.
Can a Data Matrix be damaged?
Yes, a Data Matrix can often still be decoded even when significantly damaged. Data Matrix (ECC200) uses the Reed-Solomon error correction algorithm, so ECC200 Data Matrix codes remain decodable even if up to 50% of their modules are damaged.
Using RasterEdge C# Data Matrix barcode reader library, you can scan and decode a partial damaged Data Matrix
barcode images in C# class.
How do you scan GS1 data from a Data Matrix code?
To read GS1 data, you need a scanner or software that is configured to interpret the GS1 standards. Any Data Matrix encoding GS1 data must comply with GS1 standards.
Using XImage.Barcode Reader C# library, you can easily decode well formated GS1 data messages from Data Matrix
barcode images in C# ASP.NET, MVC, Windows Forms, and WPF applications.