# BarcodeScanning

public class **BarcodeScanning** extends [Object](https://developer.android.com/reference/java/lang/Object.html)  
Entry point to get a `https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner`
for recognizing barcodes (in a variety of 1D and 2D formats) in a supplied `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage`.

A `https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner`
is created via `https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanning#getClient(com.google.mlkit.vision.barcode.BarcodeScannerOptions)` or `https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/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 `https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/common/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
`https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage`
from a `https://developer.android.com/reference/android/graphics/Bitmap.html`,
`https://developer.android.com/reference/java/nio/ByteBuffer.html`, etc. See
`https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage`
documentation for more details. For example, the code below creates an `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage`
from an `https://developer.android.com/reference/android/media/Image.html`.

     InputImage image = InputImage.fromMediaImage(mediaImage, rotationDegrees); 

Then the code below can scan barcodes in the supplied `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage`.

     Task<List<Barcode>> task = barcodeScannerClient.process(image);
     task.addOnSuccessListener(...).addOnFailureListener(...); 

### Public Method Summary

|---|---|
| static [BarcodeScanner](https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner) | [getClient](https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanning#getClient(com.google.mlkit.vision.barcode.BarcodeScannerOptions))([BarcodeScannerOptions](https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScannerOptions) options) Creates a new instance of barcode scanner with the specified options. |
| static [BarcodeScanner](https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner) | [getClient](https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanning#getClient())() Creates a new instance of barcode scanner with the default options. |

### Inherited Method Summary

From class java.lang.Object

|---|---|
| [Object](https://developer.android.com/reference/java/lang/Object.html) | clone() |
| boolean | equals([Object](https://developer.android.com/reference/java/lang/Object.html) arg0) |
| void | finalize() |
| final [Class](https://developer.android.com/reference/java/lang/Class.html)\<?\> | getClass() |
| int | hashCode() |
| final void | notify() |
| final void | notifyAll() |
| [String](https://developer.android.com/reference/java/lang/String.html) | toString() |
| final void | wait(long arg0, int arg1) |
| final void | wait(long arg0) |
| final void | wait() |

## Public Methods

#### public static [BarcodeScanner](https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner)
**getClient** ([BarcodeScannerOptions](https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScannerOptions) options)

Creates a new instance of barcode scanner with the specified options.

To release the resources associated with a `https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner`,
you need to ensure that `https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner#close()`
is called on the resulting `https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner`
object once it will no longer be used.

#### public static [BarcodeScanner](https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner)
**getClient** ()

Creates a new instance of barcode scanner with the default options.

To release the resources associated with a `https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner`,
you need to ensure that `https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner#close()`
is called on the resulting `https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner`
object once it will no longer be used.