How to Scan a Barcode Image in Java
Use an API to scan or look up a barcode. Supported barcode types include AZTEC, CODABAR, CODE_39, CODE_93, CODE_128, DATA_MATRIX, EAN_8, EAN_13, ITF, MAXICODE, PDF_417, QR_CODE, RSS_14, RSS_EXPANDED, UPC_A, UPC_E, All_1D, UPC_EAN_EXTENSION, MSI, PLESSEY, and IMB.
Join the DZone community and get the full member experience.Join For Free
From manufacturing, all the way to point of sale (POS), barcode scanning allows for the accurate tracking and delivering of inventory and products according their order specifications. In a warehouse setting, this tool may allow workers to ensure they are selecting and adding the correct parts to a product or product order according to purchaser requests, and in shipping, it provides for the accurate maintenance of inventory manifests. For organizations outside of commerce such as hospitals, barcode scanning technology can be used to confirm that the appropriate medications are distributed efficiently to the correct patients, mitigating the risk of user error.
The following Barcode APIs will allow you to use Barcode data to retrieve information on a product automatically in two ways: image scanning and text string input. The goal for this to tutorial is to increase your organizational efficiency and improve your product output by automating inventory and purchase processes through an in-house application or POS.
The first API provides a function for barcode scanning, in which an input image can scanned for barcode information. It supports many barcode types including AZTEC, CODABAR, CODE_39, CODE_93, CODE_128, DATA_MATRIX, EAN_8, EAN_13, ITF, MAXICODE, PDF_417, QR_CODE, RSS_14, RSS_EXPANDED, UPC_A, UPC_E, All_1D, UPC_EAN_EXTENSION, MSI, PLESSEY, and IMB. Common image file formats such as PNG and JPG are supported as input.
To start this function, we first need to install our library with Maven or Gradle. Start by adding a Jitpack reference to the repository in pom.xml:
Then, add a reference to the dependency:
To install with Gradle, add this in your root build.gradle at the end of repositories:
Then, add the dependency in build.gradle:
After install, we can add our imports to the file and call our function:
Your output for this function should return values for whether it was employed successfully, the type of barcode scanned, and the raw text description of the represented item. To ensure that the API functions properly, you will need to verify that:
- Your input file is valid, and that the file type is supported by the function.
- Your API Key has been properly inserted into the code block. This can be retrieved at no cost on the Cloudmersive website and will provide access to 800 monthly calls across our library of APIs.
If you need to input barcode information for a product but are unable to scan an image due to smudged or absent characters, the second API we are going to show you will help keep your operations running smoothly. With this API, you can quickly and easily look up an EAN barcode value to return product data.
As shown above, we first need to install our library through Maven or Gradle, and then we can add our imports to our file. After this, we can call the function:
Upon input, this function will inform you whether it was successfully activated, if there are any matches to the input EAN value, and the title or description of the product.
With these APIs, you can ensure that your operations run smoothly from start to finish and that your clients always receive exactly what they order.
Opinions expressed by DZone contributors are their own.