C# Data Matrix Reader Introduction
C# Data Matrix Reader SDK is a high performance C# linear and 2d barcode recognition SDK for Microsoft Visual Studio C#.NET platform.
Scan and read Data Matrix barcodes from image files is one of the barcode decoding functions in .NET Barcode Reader component. To help .net developers easiy integrate barcode reader control into your .net projects, we provide detailed online tutorial for
- Barcode Reader for C#
- Read barcode in asp.net c#
- Read barcode in c# windows application
- Barcode Reader for .NET
- Barcode Reader for VB.NET
C#.NET Barcode Reader component supports scanning and reading 20+ linear, 2d barcodes, including
You may also be interested in:
- Java Barcode Reader | Java Barcode Generator | .NET Barcode Generator | C# Barcode Generator
- ASP.NET Barcode Generator | VB.NET Barcode Generator
Install C#.NET Barcode Reader Control to Your C# project
- Copy OnBarcode.Barcode.BarcodeScanner.dll to your C#.NET project folder (do not copy dll file to your project bin folder).
- Add OnBarcode.BarcodeReader.dll to your C# project reference.
Reading Data Matrix in C# Class
Call
BarcodeScanner.Scan() method in your C# class,
and pass your barcode image file path or in Stream object, and Data Matrix barcode type (BarcodeType.Data Matrix) as method parameters.
string[] datas = BarcodeScanner.Scan("data-matrix-image.gif", BarcodeType.DataMatrix);
| Read Data Matrix in Square Shape | Read Data Matrix in Rectangle Shape |
|
|
|
Read Multiple Data Matrixs from a Single Image |
|
|
|
How to extract scanned Data Matrix barcode property information in C#?
After you have got the scanned Data Matrix in
BarcodeDetail object, you can explore the following Data Matrix barcode
property information using method GetBarcodeProps()
- FormatMode. Get scanned Data Matrix format mode used in encoding.
- DataMode. Get scanned Data Matrix encoding data mode. If mixed, it will return
DataMatrixDataMode.Mix - IsStructuredAppend. Indicate if Data Matrix contains structure append block.
- SymbolPosition. If Data Matrix is in Structured Append mode, get it's symbol position. Start from 1.
- SymbolCount. If Data Matrix is in Structured Append mode, get number of symbols in the group.
- FileID. If Data Matrix is in Structured Append mode, get file identification. 2 codewords with range 1 to 254.
ScanOptions ops = new ScanOptions(BarcodeType.DataMatrix); BarcodeDetail[] result = BarcodeScanner.Scan(imgFilePath, ops); if (result != null && result.Length > 0) { foreach (BarcodeDetail b in result) { Console.WriteLine("Message: {0}", b.GetMessage()); if (b.Type == BarcodeType.DataMatrix) { DataMatrixProps props = (DataMatrixProps)b.GetBarcodeProps(); // Get format mode used in encoding. Console.WriteLine("Format Mode: {0}", props.FormatMode.ToString()); // Get data mode used in encoding. // DataMatrixDataMode.Mix for more than 1 data modes used. Console.WriteLine("Data Mode: {0}", props.DataMode.ToString()); // Indicate if it contains structure append block. Console.WriteLine("Is Structure Append: {0}", props.IsStructuredAppend); if (props.IsStructuredAppend) { // Get symbol position. Start from 1. Console.WriteLine("Symbol Position: {0}", props.SymbolPosition); // Get number of symbols in the group. Console.WriteLine("Symbol Count: {0}", props.SymbolCount); // Get file identification. // 2 codewords with range 1 to 254. Console.WriteLine("File ID: {0},{1}", props.FileID[0], props.FileID[1]); } } } }
How to decode and parse scanned Data Matrix data in C#?
Data Matrix ISO and GS1 standards support the following data encoding
- ASCII characters. Including digits (0-9), uppercase letters (A-Z), lowercase letters (a-z), some special characters and control characters.
- Unicode text
- Binary data. It may contain compressed information, data from database.
- GS1 data message. Including one or more combinations of GS1 Application Identifier and its data.
ASCII characters
OnBarcode C# Barcode Reader library allows you easily to extract ASCII characters (with printable and non-printable chars) from Data Matrix barcode
using method
GetASCIITextMessage in
class BarcodeDetail.
BarcodeDetail[] datas = BarcodeScanner.ScanInDetails( "C://Input//data-matrix-demo.png", BarcodeType.DataMatrix); foreach (BarcodeDetail obj in datas) { Debug.WriteLine(" Barcode Text: " + obj.GetASCIITextMessage()); }
Unicode text
After you have scanned and detected the Data Matrix barcode information in
BarcodeDetail objects, you can
get the Unicode text using the following steps in C# source codes.
- Use method
GetDataBytesto get the binary data from the Data Matrix row data scanned. - Get Unicode text string by using right text encoding. Most of the Unicode text encoding are using
UTF8encode.
BarcodeDetail[] datas = BarcodeScanner.ScanInDetails("data-matrix-unicode-demo.png", BarcodeType.DataMatrix); for (int j = 0; j < datas.Length; j++) { byte[] dataInBytes = datas[j].GetDataBytes(); string textMsgDecoded = System.Text.Encoding.UTF8.GetString(dataInBytes); Console.WriteLine("message: " + textMsgDecoded); }
Binary data
In the returned barcode information
BarcodeDetail object, call
method GetDataBytes to extract the binary data from the Data Matrix raw data in C# project.
BarcodeDetail[] datas = BarcodeScanner.ScanInDetails("data-matrix-unicode-demo.png", BarcodeType.DataMatrix); for (int j = 0; j < datas.Length; j++) { byte[] dataInBytes = datas[j].GetDataBytes(); }
GS1 data message
To scan and extract GS1 data message from a GS1 Data Matrix barcode image, you need follow the steps below using C# Barcode Reader library in your
C# ASP.NET, WinForms projects.
- Create a
ScanOptionsobject with barcode formatBarcodeType.DataMatrixspecified. - Apply scan option
EnableGS1to true. The barcode library will detect Data Matrix and extract raw data and parse to GS1 data message in C# project. - In the scanned
BarcodeDetailobject, call the value of parameterIsGS1Compitableto determine whether it is GS1 data. - Use method
GetMessageto get the formatted GS1 data message in C# application.
ScanOptions opts = new ScanOptions(BarcodeType.DataMatrix); opts.EnableGS1 = true; BarcodeDetail[] result = BarcodeScanner.Scan("data-matrix-gs1-sample.png", opts); foreach (BarcodeDetail b in result) { // Indicate if the barcode is conform to GS1 specification. if (b.IsGS1Compitable) { // Get message in string format. // Eg. "(415)5412345678908(3911)710125" String msg = b.GetMessage(); Console.WriteLine("Data: '{0}'", b.Data); Console.WriteLine("Message: {0}", msg); } }
Common Asked Questions
How to install a Data Matrix reader library in an ASP.NET or WinForms project?
You can manually download the free trial version of C# Barcode Reader library dll from website, and add the Data Matrix scanner dll to the .NET project reference.
Or you can also install the OnBarcode C# Barcode Reader library nuget package through NuGet Package Manager in Visual Studio.
Can I read Data Matrix from image file and image object in memory in C# project?
Yes. You can read, scan Data Matrix from an image file or image data in Stream object or byte array using method
BarcodeScanner.Scan() in C# ASP.NET, MVC, WinForms, WPF web and desktop application. The method will load, scan and decode all Data Matrix and other barcode formats from the image content in C# project.
Is it possible to read multiple Data Matrix barcodes or with other barcode formats from a single image file?
Yes. The C# Barcode Reader library supports read and detect multiple Data Matrix barcodes from a single image file, and also scan and decode multiple Data Matrix and
other specified barcode formats' data from an image file in C# application. You will get each scanned barcode's value, barcode format, location, rotation in the
BarcodeDetail object.
Does C# Data Matrix Scanner library support rotated Data Matrix barcode image?
Yes. The Barcode library will automatically scan and detect rotated Data Matrix barcodes from the image file in C# ASP.NET, Windows applications.
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 scanner library, you will quickly scan, and decode Data Matrix code from barcode image files in C# ASP.NET Core, MVC, Windows Forms, WPF apps.
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 Reader library will scan and recognize Data Matrix barcode codes from image files in C# web and Windows apps.
Can you scan a Data Matrix?
Yes. You can use your smartphone (iPhone or Android phone) installed app to scan and decode the Data Matrix code from images.
If you are a C# developer, you can use OnBarcode C# barcode library to build a Windows or web app to scan and recognize Data Matrix code from barcode images.
Can a Data Matrix be damaged?
Yes. a Data Matrix barcode can be damaged. Data Matrix (ECC200) is using the Reed-Solomon algorithm for error correction.
A ECC200 Data Matrix barcode image can still be decodable when upto 50% of the Data Matrix bar modules are damaged.
Using OnBarcode C# Barcode Scanner library, you can easily scan and read Data Matrix text from a damaged Data Matrix barcode image in C# app.
How to scan GS1 data information from Data Matrix?
Data Matrix barcode supports GS1 System. The Data Matrix with GS1 data encoded should follow the GS1 stanadard.
OnBarcode C# Barcode Reader library supports scan and read GS1 data text from Data Matrix images in C# ASP.NET, MVC, Windows applications.
What image formats are supported using C# Data Matrix Barcode Reader library?
C# Barcode Reader library supports multiple raster image formats, such as bitmap, jpeg, png, gif, multi-page TIFF image from image file path,
in Stream object or byte array in C# .NET projects.
How to scan and read binary data from Data Matrix barcode image in C#?
Using C# Barcode Reader library, you can use method
BarcodeDetail.GetDataBytes() to extract binary data from Data Matrix image.
Can I get the Data Matrix locations in the image after they are scanned by the barcode library?
Yes. For each scanned Data Matrix barcode, you will get one
BarcodeDetail object. The Data Matrix position information is stored in
property
X1, Y1, X2, Y2,
X3, Y3, X4, Y4, which define the four positions inside the Data Matrix image.
Besides Data Matrix, does C# Barcode Reader library support other 2d, and 1d barcode formats?
OnBarcode C# Barcode Reader library supports all major popular 2d and linear barcode formats, including QR Code (both ISO and GS1 standard),
Data Matrix (both ISO and GS1 standard), Code 128, GS1-128, EAN/UPC with add-on, Code 39, PDF417 and other barcode types.
Using C# Barcode library, you can easily scan and detect all supported barcode formats using
BarcodeType.All in C# application.
How to improve Data Matrix scanning speed in C# ASP.NET web or Windows application?
C# Barcode Reader library procodes mutliple scanning options to speed up the barcode reading, such as
specified barcode scanning direction, scanning interval, partial image region scanning, multi-thread and async barcode scanning in C# ASP.NET, MVC,
WinForms, WPF, console applications.