Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class BarcodeScanner
- Object
- BarcodeScanner
ImplementsAutoCloseable, VisionAnalyzer<Barcode[]>
Decodes barcodes and QR codes out of a still image or a camera frame.
Scanning a picture the user already has:
BarcodeScanner scanner = new BarcodeScanner();
if (!scanner.isSupported()) {
ToastBar.showErrorMessage("This device cannot decode barcodes");
scanner.close();
return;
}
scanner.process(VisionImage.fromFile(photoPath)).ready(codes -> {
for (Barcode code : codes) {
Log.p(code.getFormat() + ": " + code.getValue());
}
scanner.close();
}).except(error -> {
Log.e(error);
scanner.close();
});For scanning with the camera there is usually no reason to wire this up
yourself. CodeScanner.scan() is a whole scanner screen in one call,
and VisionCameraView embeds the live preview in a form of your own:
VisionCameraView<Barcode[]> view =
new VisionCameraView<Barcode[]>(new BarcodeScanner());
view.setListener(new VisionPipelineListener<Barcode[]>() {
public void result(Barcode[] codes, VisionImage source) {
if (codes.length > 0) {
found(codes[0]);
}
}
public void error(Throwable error) {
Log.e(error);
}
});Create one analyzer and reuse it for a sequence of images; it keeps the native detector alive between calls. Close it when you are finished.
A PDF417 is reported only once two frames have read it identically, since
one printed with little error correction (level 0, as on many payment
slips) misreads into plausible wrong payloads; see
VisionOptions.strictBarcodes(boolean) to change that. This default
applies to camera frames (VisionImage.fromCameraFrame, and every
frame a VisionCameraView or VisionPipeline analyzes); a still
image is reported as decoded.
Constructors
public BarcodeScanner() | Creates an analyzer using the platform default backend and options. |
public BarcodeScanner(VisionOptions options) | Creates a reusable analyzer with explicit backend and result options. |
Methods
public final synchronized boolean isSupported() | Tests the exact feature/backend pair configured for this analyzer. |
public final synchronized AsyncResource<Barcode[]> process(VisionImage image) | Starts one analysis using the retained native backend. |
public final synchronized void close() | Idempotently releases the retained native backend. |
Inherited methods
Constructor details
BarcodeScanner
public BarcodeScanner()See also
BarcodeScanner
public BarcodeScanner(VisionOptions options)Parameters
optionsVisionOptions- configuration captured by this analyzer;
nulluses defaults
Method details
isSupported
public final synchronized boolean isSupported()Returns
process
public final synchronized AsyncResource<Barcode[]> process(VisionImage image)Parameters
imageVisionImage- immutable encoded or raw input
Returns
close
public final synchronized void close()