Quick to Read Data Matrix in VB.NET WinForms, WPF application
Here we will learn how to scan and recognize Data Matrix barcodes using the VB.NET Barcode Reader library. It supports both image file paths and Stream (byte-based data transport object) inputs, and is fully compatible with VB.NET, Windows Forms and WPF applications.
You can perform barcode recognition by calling the
You can perform barcode recognition by calling the
BarcodeScanner.Scan() method. This method accepts a local image file path or
a Stream object, together with the target barcode type as parameters.
- Call the core scanning method
BarcodeScanner.Scan(). - Pass the barcode image source (file path or Stream).
- Specify the barcode format as
BarcodeType.DataMatrix(2D matrix barcode format). - The method returns a string array containing all decoded Data Matrix data.
Dim datas As String() = BarcodeScanner.Scan( "data-matrix-image.gif", BarcodeType.DataMatrix)
Read Scanned Data Matrix Information in VB.NET
Now we will explain how to retrieve advanced Data Matrix (2D matrix barcode symbology) properties from the
After scanning barcodes and obtaining the
The VB.NET example codes explain how to extract the scanned Data Matrix metadata information.
BarcodeDetail (barcode metadata entity) object in VB.NET desktop applications.
After scanning barcodes and obtaining the
BarcodeDetail object, you can use the GetBarcodeProps() method to obtain extended Data Matrix barcode properties stored in DataMatrixProps object. These properties provide detailed encoding and structural information.
FormatMode: Gets the Data Matrix format mode used for barcode encoding.DataMode: Gets the Data Matrix encoding data mode. ReturnsDataMatrixDataMode.Mixif multiple modes are used.IsStructuredAppend: Indicates whether the Data Matrix barcode uses Structured Append mode.SymbolPosition: Gets the position index of the barcode in Structured Append mode (starting at 1).SymbolCount: Gets the total number of barcode symbols in the Structured Append group.FileID: Gets the 2-codeword file identifier (value range: 1 to 254) in Structured Append mode.
The VB.NET example codes explain how to extract the scanned Data Matrix metadata information.
- Initialize
ScanOptions(scanning configuration class) and set the barcode type to Data Matrix. - Call
BarcodeScanner.Scan()to obtain theBarcodeDetailarray. - Check for valid scan results.
- Traverse the results and use
GetBarcodeProps()to getDataMatrixProps(Data Matrix extended property class). - Read and output all Data Matrix specific properties.
' Initialize scanning configuration for Data Matrix barcode Dim scanOps As New ScanOptions(BarcodeType.DataMatrix) ' Execute barcode scanning Dim scanResult As BarcodeDetail() = BarcodeScanner.Scan(imgFilePath, scanOps) ' Check if valid barcode results are returned If scanResult IsNot Nothing AndAlso scanResult.Length > 0 Then ' Iterate all scanned barcode records For Each barcode As BarcodeDetail In scanResult ' Output barcode content message Console.WriteLine("Message: {0}", barcode.GetMessage()) ' Check if the barcode type is Data Matrix If barcode.Type = BarcodeType.DataMatrix Then ' Get Data Matrix extended properties Dim dataMatrixProps As DataMatrixProps = CType(barcode.GetBarcodeProps(), DataMatrixProps) ' Output basic encoding properties Console.WriteLine("Format Mode: {0}", dataMatrixProps.FormatMode.ToString()) Console.WriteLine("Data Mode: {0}", dataMatrixProps.DataMode.ToString()) Console.WriteLine("Is Structure Append: {0}", dataMatrixProps.IsStructuredAppend) ' Read Structured Append properties if enabled If dataMatrixProps.IsStructuredAppend Then Console.WriteLine("Symbol Position: {0}", dataMatrixProps.SymbolPosition) Console.WriteLine("Symbol Count: {0}", dataMatrixProps.SymbolCount) Console.WriteLine("File ID: {0},{1}", dataMatrixProps.FileID(0), dataMatrixProps.FileID(1)) End If End If Next End If
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.
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
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
BarcodeDetailarray 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
Most Unicode-based Data Matrix barcodes use UTF8 encoding for text storage.
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
UTF8encoding. - 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
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
BarcodeDetailarray 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
EnableGS1property toTrueto activate GS1 data parsing. - Call
BarcodeScanner.Scan()to process the barcode image. - Check the
IsGS1Compatibleproperty 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
Common Asked Questions
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.