Easily Scan and Recognize an Image of a Barcode using Java

Cloudmersive
1 min readApr 21, 2022

--

Want to enjoy the true ease and convenience of barcodes? Give our Barcode scanning API a try. It’ll recognize dozens of different types of barcodes and return information about the relevant product in a raw text string. You can take advantage of this API easily using ready-to-run code provided in Java below.

First you’ll need to install the Java SDK with Maven (instructions for Gradle included on our API Console page). Add a reference to the pom.xml repository:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Next, add one to the dependency:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>

Now one final step — add the import classes and call the function:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.BarcodeScanApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");
BarcodeScanApi apiInstance = new BarcodeScanApi();
File imageFile = new File("/path/to/inputfile"); // File | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.
try {
BarcodeScanResult result = apiInstance.barcodeScanImage(imageFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling BarcodeScanApi#barcodeScanImage");
e.printStackTrace();
}

Easy as pie. If it’s your first time using a Cloudmersive API, you’ll need an API key — head to our website (www.cloudmersive.com) and create a free account with zero financial commitments to receive one.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet