AI-generated Key Takeaways
-
BarcodeScanner is an interface that recognizes various 1D and 2D barcode formats in a supplied InputImage.
-
A BarcodeScanner instance is created using BarcodeScanning.getClient(), with the option to specify barcode formats for better performance.
-
To scan barcodes, an InputImage must first be created from sources like a Bitmap or ByteBuffer.
-
The process method is used to detect barcodes from the prepared InputImage, returning a Task with a list of Barcode objects.
-
The BarcodeScanner should be closed using the close method to release resources when no longer needed.
Recognizes barcodes (in a variety of 1D and 2D formats) in a supplied InputImage
.
A BarcodeScanner
is created via
BarcodeScanning.getClient(BarcodeScannerOptions)
or BarcodeScanning.getClient()
.
The default option is not recommended because it tries to scan all barcode formats, which is
slow. For example, the code below creates a barcode scanner for Barcode.FORMAT_PDF417
.
BarcodeScanner barcodeScanner =
BarcodeScanning.getClient(
new BarcodeScannerOptions.Builder()
.setBarcodeFormats(Barcode.FORMAT_PDF417)
.build());
To perform barcode scanning in an image, you first need to create an instance of
InputImage
from a Bitmap
,
ByteBuffer
, etc. See
InputImage
documentation for more details. For example, the code below creates an InputImage
from an Image
.
InputImage image = InputImage.fromMediaImage(mediaImage, rotationDegrees);
Then the code below can scan barcodes in the supplied InputImage
.
Task<List<Barcode>> task = barcodeScanner.process(image);
task.addOnSuccessListener(...).addOnFailureListener(...);
Public Method Summary
abstract void |
close()
Closes the scanner and releases its resources.
|
abstract Task<List<Barcode>> | |
abstract Task<List<Barcode>> |
Inherited Method Summary
Public Methods
public abstract void close ()
Closes the scanner and releases its resources.
public abstract Task<List<Barcode>> process (MlImage image)
Detects barcodes from the supplied image.
This is an experimental API in beta version.
Create an MlImage
object using one of MlImage
's
builder methods. See MlImage
documentation for more details.
To get the best detection result, we recommend the following:
- The barcode covers most of the image.
- Narrow down the barcode formats in
BarcodeScannerOptions
.
public abstract Task<List<Barcode>> process (InputImage image)
Detects barcodes from the supplied image.
Create an InputImage
object using one of InputImage
's
factory methods. See InputImage
documentation for more details.
To get the best detection result, we recommend the following:
- The barcode covers most of the image.
- Narrow down the barcode formats in
BarcodeScannerOptions
.