How to decode and parse scanned Data Matrix data in VB.NET?
Here we will explain supported data encoding types for Data Matrix (ISO & GS1 compliant 2D barcode) and demonstrates how to scan and parse Data Matrix barcode values using VB.NET.
Data Matrix barcodes following ISO (International Organization for Standardization) and GS1 (Global Standard 1, supply chain barcode standard) support multiple data encoding formats.
Supported Encoding Categories
- ASCII Characters
Includes digits (0-9), uppercase letters (A-Z), lowercase letters (a-z).
Also includes special characters and control characters.
- Unicode Text
Supports multi-language text and universal character encoding.
- Binary Data
Stores compressed information and database-derived data.
-
GS1 Data Message
Contains one or more combinations of GS1 Application Identifier (AI) and corresponding data.
Scan and parse ASCII chars from Data Matrix
The VB.NET Barcode Reader library supports decoding ASCII data from Data Matrix barcodes.
You can retrieve full ASCII text by using the
GetASCIITextMessage() method from the
BarcodeDetail class.
- Call
BarcodeScanner.ScanInDetails() to scan the Data Matrix barcode image.
- Obtain the
BarcodeDetail array that stores full Data Matrix barcode information.
- Iterate through the result array.
- Invoke
GetASCIITextMessage() to extract ASCII data (including both printable and non-printable characters).
' Scan Data Matrix barcode and return detailed barcode information
Dim barcodeDatas As BarcodeDetail() = BarcodeScanner.ScanInDetails(
"C:\Input\data-matrix-demo.png", BarcodeType.DataMatrix)
' Iterate all barcode results and output ASCII text
For Each barcodeObj As BarcodeDetail In barcodeDatas
' Extract and print ASCII text message
Debug.WriteLine("Barcode Text: " & barcodeObj.GetASCIITextMessage())
Next
Scan and parse Unicode text from Data Matrix
After retrieving barcode information via the
BarcodeDetail (barcode metadata entity) object, you can extract Unicode text with a structured workflow.
Most Unicode-based Data Matrix barcodes use UTF8 encoding for text storage.
- Call
BarcodeScanner.ScanInDetails() to read the Data Matrix barcode image.
- Use the
GetDataBytes() method to retrieve raw binary data from the barcode.
- Convert the byte array to a readable string using
UTF8 encoding.
- Output the decoded Unicode text message.
' Scan Data Matrix barcode and get detailed barcode information
Dim barcodeDatas As BarcodeDetail() = BarcodeScanner.ScanInDetails(
"data-matrix-unicode-demo.png", BarcodeType.DataMatrix)
' Loop through all scanned barcode results
For j As Integer = 0 To barcodeDatas.Length - 1
' Get raw binary data from the barcode
Dim dataInBytes As Byte() = barcodeDatas(j).GetDataBytes()
' Convert byte array to UTF8 Unicode string
Dim textMsgDecoded As String = System.Text.Encoding.UTF8.GetString(dataInBytes)
' Output the decoded message
Console.WriteLine("message: " & textMsgDecoded)
Next
Scan and parse binary data from Data Matrix
You can extract raw binary data (raw byte-format data stored in 2D barcodes) directly from the scanned barcode result.
Use the
GetDataBytes() method provided by the
BarcodeDetail class.
This method returns a byte array containing the original raw data from the Data Matrix barcode.
- Call
BarcodeScanner.ScanInDetails() to scan the Data Matrix barcode image.
- Obtain the
BarcodeDetail array that stores complete barcode information.
- Traverse the result array using a loop structure.
- Invoke the
GetDataBytes() method to get raw binary byte array data.
' Scan Data Matrix barcode and return detailed barcode information
Dim barcodeDatas As BarcodeDetail() = BarcodeScanner.ScanInDetails(
"data-matrix-unicode-demo.png", BarcodeType.DataMatrix)
' Iterate all barcode results and extract binary data
For j As Integer = 0 To barcodeDatas.Length - 1
' Extract raw binary data from barcode detail object
Dim dataInBytes As Byte() = barcodeDatas(j).GetDataBytes()
Next
Scan and parse GS1 text message from Data Matrix
To extract GS1 data correctly, you must enable GS1 parsing in the scanning configuration.The VB.NET Barcode Reader library automatically parses raw barcode data into structured GS1 format when enabled.
- Create a
ScanOptions (scanning configuration class) object and set the barcode type to DataMatrix.
- Set the
EnableGS1 property to True to activate GS1 data parsing.
- Call
BarcodeScanner.Scan() to process the barcode image.
- Check the
IsGS1Compatible property to verify GS1 compliance.
- Use the
GetMessage() method to retrieve the formatted GS1 data string.
' Execute barcode scanning with GS1 enabled
Dim result As BarcodeDetail() = BarcodeScanner.Scan("data-matrix-gs1-sample.png", opts)
' Iterate all scanned barcode results
For Each b As BarcodeDetail In result
' Check if the barcode supports GS1 standard
If b.IsGS1Compatible Then
' Get formatted GS1 data message
' Example output: (415)5412345678908(3911)710125
Dim msg As String = b.GetMessage()
' Output GS1 raw data and formatted message
Console.WriteLine("Data: '{0}'", b.Data)
Console.WriteLine("Message: {0}", msg)
End If
Next
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 VB.NET barcode scanner library, you will quickly read, scan, and decode Data Matrix code from barcode image files in Visual Basic class, console app, Windows Forms, WPF applications.
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.
VB.NET Barcode Reader library will scan and recognize Data Matrix barcode codes from image files in VB.NET console and Windows applications using Visual Studio .NET IDE.
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 visual basic developer, you can use OnBarcode VB.NET barcode decoder library to build a Windows 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 VB.NET Barcode Scanner library, you can easily scan and read Data Matrix text from a damaged Data Matrix barcode image in VB.NET 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 VB.NET Barcode Reader library supports scan and read GS1 data text from Data Matrix images in Visual Basic WPF, Windows Forms, Console projects.