Java Barcode Reader Install & Requirement
Requirement
Install
To read Tiff and bitmap image, you need two extra jars from Sun Microsystem, see how to read barcodes from tiff and bitmap images.
Install Licensed Jar
- Remove the trial version jar from your Java project. You need clean your project cached content also.
- Add the downloaded licensed jar file OnBarcode.BarcodeReader.jar to your project reference.
Compare Barcode library Trail and Licensed jar
There is only one limit in the trial version of barcode jar. The first character or digit from returned barcode data is randomly generated. In the licensed sdk, we have removed the limit.
Barcode Reader Library all Supported Barcode Formats
public enum OnBarcode.Barcode.BarcodeScanner.BarcodeType { AustraliaPost, EAN8, ITF14, RM4SCC, Codabar, EAN13, Leitcode, UPCA, Code39, Identcode, PatchCode, UPCE, Code39Extension, IntelligentMail, PDF417, All Code93, Interleaved2of5, Planet, Code128, ISBN, Postnet, DataMatrix, ISSN, QRCode, }
How to read barcodes using Java Barcode Reader?
BarcodeScanner.Scan() to quickly scan and
decode the barcodes from the image file in Java application.
Here is the sample Java code to decode a Code 128 barcode data from image file.
String[] datas = BarcodeScanner.Scan("code128-barcode.png", BarcodeType.Code128);
Pass your barcode image file, and barcode type to BarcodeReader, and it will return barcode datas.
Scan barcodes from Java image object
RenderedImage in memory.
java.awt.image.RenderedImage renderedImage = ImageIO.read(new File("code128-barcode.png")); String[] datas = BarcodeScanner.Scan(renderedImage, BarcodeType.Code128);
Class ScanOptions and BarcodeDetail in Java
ScanOptions
ScanOptions in Java Barcode Scanner library, you can easily customize the barcode reading options to enhance reading speed, improve recognition rate.
List of options in ScanOptions
- setScanSingle(): enable to scan maximum one barcode per image file. It will improve the reading speed, if there is only one barcode in one image file. The barcode library will stop scanning the remaining image area, once it has detected a valid barcode.
- SetScanRegions(): enable to scan specified regions inside the image file. It will speed up the reading speed, and improve the reading accuracy.
- SetMaxMultiThreadCount(): enable to scan barcodes using multi-threading in Java application.
- setEnableGS1(): enable to read and parse GS1 data elements from GS1 compatible barcodes, such as QR Code, Data Matrix, GS1-128, GS1 DataBar. More details, view here: How to read and parse GS1 barcode image using Java?
- setScanDirection(): Specify the barcode library image scanning direction to speed up the barcode reading speed.
- setStepInterval(): When defining the barcode search area, the scanning spacing is used, which indicates how many lines are scanned at a time.
- setZoomRatio(): Valid range:
0.2F - 5.0F. Default is 1.0F. Apply scanned image zooming. - setCode39WithCheckCharacter(): For Code 39 barcode only. Set it to true, if the Code 39 barcode contains check character.
BarcodeDetail
String[] datas = BarcodeScanner.Scan("code128-barcode.png", BarcodeType.Code128);
Sometimes you need know and explore more information about scanned barcode, such as barcode location on the image, barcode rotation angle.
We have included the Java class
BarcodeDetail in Java Barcode Reader library to help read and explore more information about the scanned barcode data.
In class BarcodeDetail, we have provided useful properties and methods for each
scanned barcodes.
- getRotation(): find the rotation angle about the scanned barcode.
- X1, Y1, X2, Y2, X3, Y3, X4, Y4: 8 get methods to return the detected barcode position on the image file.
- isStructuredAppend(): It is for QR Code and Data Matrix barcodes only. To identify whether the QR Code or Data Matrix barcode is in Structure Append mode.
- IsGS1Compitable(): It is for QR Code, Data Matrix and Code 128 barcodes only. To identify whether the found barcode is GS1 compatible.
- Method isMacroPDF417(): It is for PDF417 barcodes only.
- Method getDataBytes(). You can get the read barcode data in byte array.
- Method getASCIITextMessage(). You can get the returned barcode text in ASCII characters.
- Method getMessage(). You can get the scanned barcode data using default UTF8 encoding or your specified encoding format.
Java code to scan and get more barcode information from BarcodeDetail object
ScanOptions options = new ScanOptions(BarcodeType.DataMatrix); options.setScanSingle(true); BarcodeDetail[] datas = BarcodeScanner.Scan( "data-matrix-sample-image.png", options); for (BarcodeDetail obj : datas) { System.out.println("Message: '" + obj.getMessage() + "'"); // Show index and file path of the source image in the input array. // getSourceFilePath() returns empty if the input is file streams or Bitmap objects. System.out.println(" Source: Index=" + obj.getSourceIndex() + "; Source Path: " + obj.getSourceFilePath()); }
How to improve barcode reading performance using Java Barcode Reader library?
Quick to scan and read a single barcode in Java
String[] datas = BarcodeScanner.ScanSingleBarcode( "sample-code128-barcode.png", BarcodeType.Code128);
Multiple barcodes scanning in Java
String[] datas = BarcodeScanner.Scan("qrcode-barcode.png", BarcodeType.QRCode); BarcodeDetail[] datasInDetail = BarcodeScanner.ScanInDetails( "qrcode-barcode.png", BarcodeType.QRCode);
You can scan multiple barcode formats at one time in the Java web and desktop applications, and the barcode library will return all found barcodes.
The Java source code below will explain how to scan and decode QR Code and Code 128 barcodes from the image file in Java application.
ArrayList<BarcodeType> formats = new ArrayList<BarcodeType>(); formats.add(BarcodeType.QRCode); formats.add(BarcodeType.Code128); BarcodeDetail[] datas = BarcodeScanner.ScanInDetails("multiple-barcodes.png", formats);
Scan and read barcodes from specified image regions in Java
ArrayList<SRegion> regions = new ArrayList<SRegion>(); regions.add(new SRegion(0, 0, 50, 60)); String[] barcodes = BarcodeScanner.ScanRegions("qrcode-barcodes.png", BarcodeType.QRCode, regions);
Scan barcodes with specified directions in Java
ScanOptions ops = new ScanOptions(BarcodeType.Code128); ops.setScanDirection( ScanOptions.ScanDirection_LeftToRight | ScanOptions.ScanDirection_TopToBottom);
You can choose one or multiple directions combined to scan the barcodes in the Java application.
public static final int ScanDirection_Undefined = 0; public static final int ScanDirection_LeftToRight = 1; public static final int ScanDirection_TopToBottom = 2; public static final int ScanDirection_RightToLeft = 4; public static final int ScanDirection_BottomToTop = 8; public static final int ScanDirection_Horizontal = 5; public static final int ScanDirection_Vertical = 10; public static final int ScanDirection_All = 15;
Scan barcodes with customized step interval in Java
setStepInterval() in class ScanOptions to customize the scanning step interval.
The method input parameter specifies the scanning spacing, which indicates how many lines are scanned at a time.
The minimum value is 1, and every row will be scanned.
Default value: 5 (scan once every 5 lines)
The Java program below, shows how to customize the barcode image scanning step intervals to improve the reading speed.
ScanOptions ops = new ScanOptions(BarcodeType.Code128); ops.ScanDirection = ScanDirectionType.LeftToRight; ops.StepInterval = 10;
Process Complex Barcode Text Message in Java
Java Barcode Reader FAQ
How to read barcode from a specified area (rectangle) in the image?
To improve scanning speed, you can specify a rectangle area in the image for scanning barcode.
ScanOption option = new ScanOption();
/**
* specify barcode area in the scanning image
*
* x1, y1, x2, y2, valid values are from 0 to 1, inclusive.
*
* @param x1 barcode area left top point X value, % of image width
* @param y1 barcode area left top point Y value, % of image height
* @param x2 barcode area right bottom point X value, % of image width
* @param y2 barcode area right bottom point Y value, % of image height
*/
// scan top 20% of the image
option.setScanDirection(ScanOption.SCAN_FROM_TOP_TO_BOTTOM);
option.setBarcodeArea(0, 0, 1, 0.2);
String[] datas = BarcodeReader.read(new File("C:/YourBarcodeImage.gif"), BarcodeReader.EAN8, option);
- Pass your barcode image file, and barcode type, and ScanOption object to BarcodeReader, and it will return barcode datas in the specified area from the image.
For TIFF or Bitmap image reading only, developers need include two Java Advanced Imaging jars from Sun Microsystems, jai_codec.jar, jai_core.jar. Both are included under lib folder.
How to get supplement barcode data?
For barcode EAN 8, EAN 13, UPC-A, UPC-E, their barcode image may contain 2 or 5 digits supplement barcode, Java Barcode Reader will add supplement barcode data to the main barcode data.
For example, Java barcode reader will return data as "123450512345" for above sample image. The First 7 digits "1234505" is UPCE data, and the last 5 digits "12345" is UPCE supplement data.
For UPC-E barcode, usually there are 8 digits printed on the barcode label. The first digit is UPC-E number system, valid values are 0 or 1. The
next 6 digits are UPC-E data, and the last one is checksum.
Our library will return 6 digits data and the last one checksum. Developer should use the first 6
digits as UPC-E data, according to UPC-E specification.
For the above barcode image, 0 is the number system, 123450 is the UPC-E data, and 5 is the checksum. Our library will return 1234505, plus suppliment barcode 12345.
So the final output will be 123450512345.
For multi-page tiff file, Java barcode reader will scan every page in the file, and return all barcodes in all pages.
Java Barcode Reader Downloaded Package Contents
- OnBarcode.BarcodeReader.jar for Java Barcode Reader library file.
- lib contains three jars for TIFF and bitmap image.
- Software_License_Agreement.pdf for barcode library license information.
- Developer Guide.pdf developer guide.
