Basic Barcode Recognition Parameters

Overview

Class BarCodeReader in Aspose.BarCode for Java is the most important to implement barcode recognition for more than 60 symbologies. First, it is necessary to identify a barcode source that can be represented as a file, a stream, or a bitmap object. After that, target barcode types need to be specified using values from the DecodeType enum. By default, the library uses the DecodeType.ALL_SUPPORTED_TYPES setting that implies iterating over all supported barcode types to check for their presence in the source image. In this case, barcode scanning and recognition take much more time. Developers can specify explicitly not only the desired types but also a target region or regions in the source image. This allows optimizing the scanning process by avoiding areas without barcodes. Target regions can be determined using a system class called Rectangle.

In the barcode recognition process implemented in Aspose.BarCode for Java, barcode data decoding is initiated according to the special protocol after scanning the raw data from a graphical representation. Some linear and postal barcode types have passed standardization after their wide implementation, and therefore, it has led to the presence of incompatible decoding formats. To resolve possible conflicts, class BarCodeReader provides a special class called BarcodeSettings used to manage barcode decoding settings.

Basic Recognition Parameters

In Aspose.BarCode for Java, barcode reading is performed according to the following steps:

  • Determine the barcode source (image file, stream, or bitmap), e.g. set the path to a source image
  • Select target barcode types. DecodeType is set to DecodeType.ALL_SUPPORTED_TYPES by default meaning that the source image will be scanned to search for all supported barcode types; in this case, the time required to finish the barcode detection process will increase.

Aspose.BarCode for Java contains the ReadBarCodes method of class BarCodeReader that returns the result of barcode reading in an array of the BarCodeResult type.

Get Recognition Results

To load barcode recognition outputs, it is needed to call the ReadBarCodes method that provides a BarCodeResult array. Moreover, the current recognition output can be accessed through the getFoundBarCodes method that enables fetching decoding results or the getFoundCount method that returns the number of detected barcodes.

Abort Barcode Reading using Manual and Timeout Methods

Class BarCodeReader enables two special methods to stop the recognition process if it becomes unfeasible to complete. The first one is the setTimeOut method that can be called to interrupt the barcode reading process immediately after the timeout value gets exceeded. By default, the TimeOut value is set to 0.

The second way is to use the abort() method. This option is used if the recognition process has been launched in the other thread. This method does not stop the entire process and returns controls immediately.

Both aforementioned methods throw an exception called RecognitionAbortedException if the recognition process could not be finished successfully.