Spire.Barcode for Java supports to generate various types of Barcodes such as Code 128, Pdf 417, QR code etc. At the same time, it also supports to read data from the generated barcode images. This article demonstrates how to scan a barcode image using Spire.Barcode for Java.
Prerequisite:
Import Spire.Barcode.jar file
Download Spire.Barcode for Java and import Spire.Barcode.jar file into the project. The detail steps of how to import Spire.Barcode.jar can be found in this article: How to Create Barcode Using Spire.Barcode for Java.
Code:
To scan a barcode image, we can use the scan method in BarcodeScanner class.
import com.spire.barcode.BarCodeType; import com.spire.barcode.BarcodeScanner; public class SpireBarcode_test { public static void main(String[] args) throws Exception { String[] datas = BarcodeScanner.scan("C:\\code128.jpg", BarCodeType.Code_128); System.out.print(datas[0]); } }
Code 128 image:
Output: