Java Barcode Code 128 Scanner Introduction
Scanning and reading barcode Code 128 from image file is a key feature in OnBarcode
Barcode Reader for Java jar library.
Java Barcode Reader is completely developed in Java SDK 5.0, and you can easy integrate the barcode reading feature in your Java project without any registration key, activation code.
Install Code 128 Barcode Reader Java Library
- Download the free trial package or licensed software. Unzip it.
- Add OnBarcode.BarcodeReader.jar to your Java project reference.
Reading & Scanning Code 128 Barcodes in Java class
Using Java Barcode Reader library, you can easily scan and read the Code 128 barcode data from an image file. The Java codes below will explain how to
use method
BarcodeScanner.Scan() to recognize all Code 128 barcodes from an image file in Java application.
String[] datas = BarcodeScanner.Scan("code128-image.png", BarcodeType.Code128);
Scan Code 128 in image object in Java memory
You can also use use method
BarcodeScanner.Scan() to scan the image object ( java.awt.image.RenderedImage ) in memory and read all Code 128 barcodes from it in Java web and desktop applications.
RenderedImage renderedImage = ImageIO.read(new File("code128-image.png")); String[] datas = BarcodeScanner.Scan(renderedImage, BarcodeType.Code128);
Explore scanned Code 128 barcode information in Java application
Using OnBarcode Java Barcode Reader library, you can retrieve scanned Code 128 barcode properties, including:
Code 128 start and encoding code set,
Code 128 check character codeword integer value.
After get the scanned Code 128 in
After get the scanned Code 128 in
BarcodeDetail object, you can call method GetBarcodeProps() to extract
detected Code 128 barcode properties in Code128Props object.
- StartSet. Code 128 start code set in property
StartSet. Get the Code 128 start code set. It should be Code Set A, Code Set B, or Code Set C. - IsMixSet. Whether more than one Code Sets are used. If the Code 128 barcode using more than one encoding Code Sets, the property
IsMixSetwill return true. - Checksum. Code 128 checksum codeword in property
Checksum. The value is in range from 0 to 102.
BarcodeDetail[] result = BarcodeScanner.ScanInDetails( "code128-barcode.png", BarcodeType.Code128); if (result != null && result.length > 0) { for (BarcodeDetail b : result) { System.out.println("Message: " + b.getMessage()); if (b.getType() == BarcodeType.Code128) { Code128Props props = (Code128Props)b.getBarcodeProps(); // Get start Set type System.out.println("Start Set: " + props.getStartSet().toString()); // Indicate if more than one Sets are used in encoding. System.out.println("Is Mix Set: " + props.getIsMixSet()); // Checksum codeword, value in range from 0 to 102 System.out.println("Checksum: " + props.getChecksum()); } } }
How to scan and read Code 128 ASCII characters in Java?
Using Java Barcode Scanner SDK, you can call method
The Code 128 barcode image below has encoded one non-printing character (carriage return) between char 'e' and '1'.
You will get the following message in the Java IDE.
getASCIITextMessage() to scan and return non-printing ASCII characters with visual text labels replaced.
The Code 128 barcode image below has encoded one non-printing character (carriage return) between char 'e' and '1'.
BarcodeDetail[] datas = BarcodeScanner.ScanInDetails( "code128-barcode-sample.png", BarcodeType.Code128); for (int j = 0; j < datas.length; j++) { String barcodeAsciiText = datas[j].getASCIITextMessage(); }
You will get the following message in the Java IDE.
How to verify the scanned Code 128 barcode using check character in Java?
Code 128 barcode always includes one compulsory check character. When you have created a Code 128 barcode, the check character will be
calculated and applied to the printed barcode symbology.
The Code 128 check character will not be printed on the Code 128 text label area, and will not be returned by the barcode scanner device or software.
Using Java Barcode Reader library, you will get the Code 128 data characters only and will not get the check character in the returned barcode data. However you can get the scanned Code 128 barcode check character int value through
The Java barcode reader library will apply the scanned check character to verfiy the Code 128 data characters. The barcode scanner SDK will return the Code 128 barcode data if the verification is successful.
Using Java Barcode Reader library, you will get the Code 128 data characters only and will not get the check character in the returned barcode data. However you can get the scanned Code 128 barcode check character int value through
Code128Props.getChecksum() function using Java Barcode Scanner SDK.
- Call method
Code128Props.getChecksum()to get the scanned Code 128 barcode check character codeword value.
BarcodeDetail[] datas = BarcodeScanner.ScanInDetails( "code128-sample.png", BarcodeType.Code128); for (int j = 0; j < datas.length; j++) { Code128Props barcodeProps = (Code128Props)datas[j].getBarcodeProps(); int code128CheckCharValue = barcodeProps.getChecksum(); System.out.println("Code 128 check char value: " + code128CheckCharValue); }
The Java barcode reader library will apply the scanned check character to verfiy the Code 128 data characters. The barcode scanner SDK will return the Code 128 barcode data if the verification is successful.
How to scan, read GS1-128 (EAN-128) barcodes in Java?
Use the following Java source code, you could easily read all GS1 text elements from the GS1-128 barcode images.
- Choose target barcode type as
BarcodeType.Code128. GS1-128 data is using Code 128 barcode as GS1 data carrier. - Call method
BarcodeScanner.ScanInDetails()to read, scan a barcode image file to recognize all GS1-128 barcodes inside. - For all the returned scanned BarcodeDetail objects, check each barcode is a valid GS1-128 barcode using method
isGS1Compitable(). - Get the GS1 text message using
BarcodeDetail.getMessage().
BarcodeDetail[] result = BarcodeScanner.ScanInDetails( "gs1-128-barcode.png", BarcodeType.Code128); for (BarcodeDetail b : result) { // Indicate if the Code 128 is a valid GS1-128 barcode. if (b.isGS1Compitable()) { // Get message in string format. // Eg. "(00)395123451234567895(01)09501101530003" String msg = b.getMessage(); System.out.println("Raw Data: " + b.getData()); System.out.println("Text Message: " + msg); // Retrieve each AI (application identifier) and its data from the message. // Eg. // AI: 00 // Data: 395123451234567895 // AI: 01 // Data: 09501101530003 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 the barcode 128 text code?
Code 128 barcode is a high-density 1D barcode format, which encodes digits, text, control characters, and full ASCII 128 characters.
Using Java Barcode Reader library, you will be able to scan, read, recognize and decode Code 128 text from images file in Java applications.
How do you read a Code 128 barcode?
Code 128 barcodes are including four parts:
- A start character
- Code 128 data characters
- A checksum digit
- A stop character
What scanners read Code 128 barcode?
Most commercial barcode scanner devices and free or paid barcode scanner software can read Code 128 barcodes from images or printed papers.
OnBarcode Java Barcode Scanner library supports scanning and reading Code 128 barcodes in Java application on Windows, macOS and Linux.
How do I scan a Code 128 barcode?
You can easily use a barcode scanner device, a phone or pad with camera, or barcode software or library to scan, decode Code 128 text from barcode images or printed papers.
Java Barcode Reader library will enable your Java web and desktop applications to scan and recogize all Code 128 and other 2d, 1d barcodes from image files.
Java Barcode Reader library will enable your Java web and desktop applications to scan and recogize all Code 128 and other 2d, 1d barcodes from image files.
How to read Code 128 checksum digit using barcode scanner software?
According to Code 128 ISO standard (ISO/IEC 15417), barcode scanner device or software will not return the Code 128 check sum character.
OnBarcode Java Barcode Reader library
will recognize and decode the Code 128 data text without the check digit included in Java class.