BarcodeScanner

interface BarcodeScanner extends HybridObject

Represents a Barcode Scanner that uses MLKit Barcodes.

The BarcodeScanner can be used in a Frame Processor by calling scanCodes(...), or for static images by calling scanCodesInImageAsync(...).

See

Methods

scanCodes(...)

scanCodes(frame: Frame): Barcode[]

Synchronously detects Barcodes in the given Frame.

All coordinates in the Barcode are relative to the Frame's coordinate system.

You can convert Barcode coordinates to Camera coordinates using Frame.convertFramePointToCameraPoint(...), and then convert the Camera coordinates to Preview View coordinates using PreviewViewMethods.convertCameraPointToViewPoint(...).

Example

const scanner = // ...
const frame = // ...
const previewView = // ...

const barcodes = scanner.scanCodes(frame)
for (const barcode of barcodes) {
  console.log('Barcode value:', barcode.rawValue)
  for (const point of barcode.cornerPoints) {
    const cameraPoint = frame.convertFramePointToCameraPoint(point)
    const previewPoint = previewView.convertCameraPointToViewPoint(cameraPoint)
    console.log('Corner Point:', previewPoint)
  }
}

scanCodesAsync(...)

scanCodesAsync(frame: Frame): Promise<Barcode[]>

Asynchronously detects Barcodes in the given Frame.

See

scanCodes


scanCodesInImageAsync(...)

scanCodesInImageAsync(image: Image): Promise<Barcode[]>

Asynchronously detects Barcodes in the given Image.

This can be used to scan codes in an existing still image, such as an image loaded from disk, bundled resources or a URL via react-native-nitro-image.

All coordinates in the returned Barcodes are relative to the given Image's coordinate system.

Example

import { loadImage } from 'react-native-nitro-image'
import { createBarcodeScanner } from 'react-native-vision-camera-barcode-scanner'

const image = await loadImage({ url: 'https://example.com/barcode.png' })
const scanner = createBarcodeScanner({ barcodeFormats: ['all-formats'] })

try {
  const barcodes = await scanner.scanCodesInImageAsync(image)
  console.log('Barcode value:', barcodes[0]?.rawValue)
} finally {
  image.dispose()
  scanner.dispose()
}

On this page