Java Barcode Data Matrix Scanner Introduction
Scanning and reading barcode Data Matrix from image file is a key feature in OnBarcode
Barcode Scanner for Java library (single jar file).
Java Barcode Reader is completely developed in Java SDK 1.4.2, and you can easy integrate the barcode reading feature in your Java project without any registration key, activation code.
Install Barcode Library to Java Project
- Add OnBarcode.BarcodeReader.jar to your Java project reference.
Reading & Scanning Data Matrix Barcodes in Java class
Using Java Barcode Reader library, you can quickly scan and read Data Matrix barcodes from an image file using method
Besides image file, you can also pass java.awt.image.RenderedImage object to the
BarcodeScanner.Scan()
in Java application.
String[] datas = BarcodeScanner.Scan( "data-matrix-image.png", BarcodeType.DataMatrix);
Besides image file, you can also pass java.awt.image.RenderedImage object to the
Scan() method.
Scan and read all QR Code informations from an image file using Java
Using OnBarcode Java Data Matrix Barcode Reader library, you can use the property getter method to explore the following Data Matrix barcode property information in method
getBarcodeProps()
- FormatMode. Retrive Data Matrix format mode used in encoding.
- DataMode. Get scanned Data Matrix encoding data mode. If there are more than one data modes, it will return
DataMatrixDataMode.Mix - IsStructuredAppend. Indicate if Data Matrix is in structured append mode.
- 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.
BarcodeDetail[] result = BarcodeScanner.ScanInDetails( "data-matrix-image.png", BarcodeType.DataMatrix); if (result != null && result.length > 0) { for (BarcodeDetail b : result) { System.out.println("Message: " + b.getMessage()); if (b.getType() == BarcodeType.DataMatrix) { DataMatrixProps props = (DataMatrixProps)b.getBarcodeProps(); // Get format mode used in encoding. System.out.println("Format Mode: " + props.getFormatMode().toString()); // Get data mode used in encoding. // DataMatrixDataMode.Mix for more than 1 data modes used. System.out.println("Data Mode: " + props.getDataMode().toString()); // Indicate if it contains structure append block. System.out.println("Is Structure Append: " + props.isStructuredAppend()); if (props.isStructuredAppend()) { // Get symbol position. Start from 1. System.out.println("Symbol Position: " + props.getSymbolPosition()); // Get number of symbols in the group. System.out.println("Symbol Count: " + props.getSymbolCount()); // Get file identification. // 2 codewords with range 1 to 254. System.out.println("File ID 1: " + props.getFileID()[0] + "; ID 2: " + props.getFileID()[1]); } } } }
Scan and read all QR Code informations from an image file using Java
Java Data Matrix Scanner supports both Data Matrix ISO and GS1 standards. Data Matrix ISO and GS1 standards support the following text encoding
- ASCII characters. Including digits (0-9), uppercase letters (A-Z), lowercase letters (a-z), some special characters and control characters.
- Binary data. It may contain compressed information, data from database.
- Unicode text. Encoding through binary mode.
- GS1 text message. Including one or more combinations of GS1 Application Identifier and its data.
Parse ASCII Characters
OnBarcode Java Data Matrix Scanner SDK 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( "data-matrix-ascii-sample.png", BarcodeType.DataMatrix); for (int j = 0; j < datas.length; j++) { String barcodeAsciiText = datas[j].getASCIITextMessage(); }
Parse Binary and Unicode Text String
After you have scanned and recognized the Data Matrix barcode information in BarcodeDetail objects, you can get the Unicode text using the following Java example codes.
- Use method
getDataBytes()to get the binary data from the Data Matrix raw data scanned. - Get Unicode text string by using right text encoding. Most of the Unicode text encoding are using
UTF-8encoding.
BarcodeDetail[] datas = BarcodeScanner.ScanInDetails( "data-matrix-unicode-sample.png", BarcodeType.DataMatrix); for (int j = 0; j < datas.length; j++) { String textMsgDecoded = new String(datas[j].getDataBytes(), "UTF-8"); System.out.println("Unicode text: " + textMsgDecoded); }
Parse GS1 Text Message
To scan and parse GS1 text message from a standard GS1 Data Matrix image, you need follow the steps below using Java Barcode Reader library.
- Scan a Data Matrix image file with barcode format
BarcodeType.DataMatrixspecified. - In the scanned BarcodeDetail object, call the method
isGS1Compitable()to determine whether it is GS1 data. - Use method
getMessageto get the formatted GS1 text message in Java application.
BarcodeDetail[] datas = BarcodeScanner.ScanInDetails( "data-matrix-gs1-sample.png", BarcodeType.DataMatrix); for (BarcodeDetail b : datas) { // Indicate whether the Data Matrix is conform to GS1 system. if (b.isGS1Compitable()) { // Get message in string format. // Eg. "(415)5412345678908(3911)710125" String msg = b.getMessage(); System.out.println("Raw Data: " + b.getData()); System.out.println("Text Message: " + msg); // Retrieve each AI and its data from the message. // Eg. // AI: 415 // Data: 5412345678908 // AI: 3911 // Data: 710125 String[] vals = msg.split("[()]"); for (int i = 0; i < vals.length; i += 2) { System.out.println("AI: " + vals[i]); System.out.println("Data: " + vals[i + 1]); } } }
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 Java Barcode Reader library, you will quickly scan, and decode Data Matrix code from image files in Java class, JSP, Servlet web application and J2EE application.
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.
OnBarcode Java Barcode Reader library will scan and recognize Data Matrix barcode codes from image files in Java source code.
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 photo or image.
If you are a Java developer, you can use OnBarcode Java barcode scanner library to build a desktop or web application to read, scan and decode 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 Java Data Matrix Reader library, you can easily scan and decode Data Matrix code text from a damaged Data Matrix barcode image in Java projects.
How to scan GS1 data information from Data Matrix?
Data Matrix barcode supports GS1 standard. The Data Matrix with GS1 data encoded should follow the GS1 stanadard.
OnBarcode Java Barcode Reader library supports scan and read GS1 data text from Data Matrix images in Java web and desktop applications.