BarcodeScanning
Stay organized with collections
Save and categorize content based on your preferences.
Entry point to get a BarcodeScanner
for recognizing barcodes (in a variety of 1D and 2D formats) in a supplied InputImage
.
A BarcodeScanner
is created via
getClient(BarcodeScannerOptions)
or 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 = barcodeScannerClient.process(image);
task.addOnSuccessListener(...).addOnFailureListener(...);
Inherited Method Summary
From class java.lang.Object
Object
|
clone()
|
boolean |
|
void |
finalize()
|
final Class<?>
|
getClass()
|
int |
hashCode()
|
final void |
notify()
|
final void |
notifyAll()
|
String
|
toString()
|
final void |
wait(long arg0, int arg1)
|
final void |
wait(long arg0)
|
final void |
wait()
|
Public Methods
Creates a new instance of barcode scanner with the specified options.
To release the resources associated with a BarcodeScanner
,
you need to ensure that BarcodeScanner.close()
is called on the resulting BarcodeScanner
object once it will no longer be used.
Creates a new instance of barcode scanner with the default options.
To release the resources associated with a BarcodeScanner
,
you need to ensure that BarcodeScanner.close()
is called on the resulting BarcodeScanner
object once it will no longer be used.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[null,null,["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eBarcodeScanning\u003c/code\u003e is the entry point for recognizing barcodes in various formats using a \u003ccode\u003eBarcodeScanner\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eYou can create a \u003ccode\u003eBarcodeScanner\u003c/code\u003e instance with specific barcode formats or use the default options (not recommended due to slower performance).\u003c/p\u003e\n"],["\u003cp\u003eBefore scanning, create an \u003ccode\u003eInputImage\u003c/code\u003e from a source like a \u003ccode\u003eBitmap\u003c/code\u003e or \u003ccode\u003eByteBuffer\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eUse the \u003ccode\u003eprocess()\u003c/code\u003e method of the \u003ccode\u003eBarcodeScanner\u003c/code\u003e to scan the \u003ccode\u003eInputImage\u003c/code\u003e and get a \u003ccode\u003eTask\u003c/code\u003e containing the detected barcodes.\u003c/p\u003e\n"],["\u003cp\u003eRemember to call \u003ccode\u003eBarcodeScanner.close()\u003c/code\u003e when you're finished to release resources.\u003c/p\u003e\n"]]],["`BarcodeScanning` allows for barcode recognition using `BarcodeScanner`. Create a `BarcodeScanner` instance via `getClient()`, specifying `BarcodeScannerOptions` for efficiency (default scans all formats, which is slow). Use `InputImage` (from `Bitmap`, `ByteBuffer`, etc.) as input. Then, scan barcodes with `barcodeScannerClient.process(image)`, handling success/failure via listeners. Release resources using `BarcodeScanner.close()` when the scanner is no longer needed.\n"],null,["# BarcodeScanning\n\npublic class **BarcodeScanning** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nEntry point to get a [BarcodeScanner](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner)\nfor recognizing barcodes (in a variety of 1D and 2D formats) in a supplied [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage).\n\nA [BarcodeScanner](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner)\nis created via [getClient(BarcodeScannerOptions)](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanning#getClient(com.google.mlkit.vision.barcode.BarcodeScannerOptions)) or [getClient()](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanning#getClient()).\nThe default option is not recommended because it tries to scan all barcode formats, which is\nslow. For example, the code below creates a barcode scanner for [Barcode.FORMAT_PDF417](/android/reference/com/google/mlkit/vision/barcode/common/Barcode#FORMAT_PDF417). \n\n BarcodeScanner barcodeScanner =\n BarcodeScanning.getClient(\n new BarcodeScannerOptions.Builder()\n .setBarcodeFormats(Barcode.FORMAT_PDF417)\n .build()); \n\nTo perform barcode scanning in an image, you first need to create an instance of\n[InputImage](/android/reference/com/google/mlkit/vision/common/InputImage)\nfrom a [Bitmap](//developer.android.com/reference/android/graphics/Bitmap.html),\n[ByteBuffer](//developer.android.com/reference/java/nio/ByteBuffer.html), etc. See\n[InputImage](/android/reference/com/google/mlkit/vision/common/InputImage)\ndocumentation for more details. For example, the code below creates an [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage)\nfrom an [Image](//developer.android.com/reference/android/media/Image.html). \n\n InputImage image = InputImage.fromMediaImage(mediaImage, rotationDegrees); \n\nThen the code below can scan barcodes in the supplied [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage). \n\n Task\u003cList\u003cBarcode\u003e\u003e task = barcodeScannerClient.process(image);\n task.addOnSuccessListener(...).addOnFailureListener(...); \n\n### Public Method Summary\n\n|--------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static [BarcodeScanner](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner) | [getClient](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanning#getClient(com.google.mlkit.vision.barcode.BarcodeScannerOptions))([BarcodeScannerOptions](/android/reference/com/google/mlkit/vision/barcode/BarcodeScannerOptions) options) Creates a new instance of barcode scanner with the specified options. |\n| static [BarcodeScanner](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner) | [getClient](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanning#getClient())() Creates a new instance of barcode scanner with the default options. |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Methods\n--------------\n\n#### public static [BarcodeScanner](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner)\n**getClient** ([BarcodeScannerOptions](/android/reference/com/google/mlkit/vision/barcode/BarcodeScannerOptions) options)\n\nCreates a new instance of barcode scanner with the specified options.\n\nTo release the resources associated with a [BarcodeScanner](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner),\nyou need to ensure that [BarcodeScanner.close()](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner#close())\nis called on the resulting [BarcodeScanner](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner)\nobject once it will no longer be used. \n\n#### public static [BarcodeScanner](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner)\n**getClient** ()\n\nCreates a new instance of barcode scanner with the default options.\n\nTo release the resources associated with a [BarcodeScanner](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner),\nyou need to ensure that [BarcodeScanner.close()](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner#close())\nis called on the resulting [BarcodeScanner](/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner)\nobject once it will no longer be used."]]