rememberBarcodeScannerOutput
Use a Barcode Scanner CameraOutput (the equivalent of VisionCamera's useBarcodeScannerOutput).
The Barcode Scanner CameraOutput can be attached to a CameraSession (e.g. with me.nathanfallet.visioncamera.compose.rememberCamera) or to a me.nathanfallet.visioncamera.compose.Camera composable. It is kept across recompositions and recreated when the barcodeFormats or the outputResolution change, while the latest onBarcodeScanned and onError are always called, without recreating the output.
Attach to a Camera composable:
val scannerOutput = rememberBarcodeScannerOutput(
barcodeFormats = listOf(TargetBarcodeFormat.ALL_FORMATS),
onBarcodeScanned = { barcodes -> println("Scanned ${barcodes.size} barcodes!") },
onError = { error -> println("Failed to scan barcodes! $error") },
)
Camera(device = TargetCameraPosition.BACK, isActive = true, outputs = listOf(scannerOutput))Attach to a CameraSession:
val scannerOutput = rememberBarcodeScannerOutput(
barcodeFormats = listOf(TargetBarcodeFormat.ALL_FORMATS),
onBarcodeScanned = { barcodes -> println("Scanned ${barcodes.size} barcodes!") },
onError = { error -> println("Failed to scan barcodes! $error") },
)
val controller = rememberCamera(isActive = true, device = TargetCameraPosition.BACK, outputs = listOf(scannerOutput))All Barcode coordinates are in the coordinate system of the Frame they were detected in (its raw buffer). For full control over coordinate system conversions (Frame.convertFramePointToCameraPoint, then the preview's convertCameraPointToViewPoint), scan Frames yourself with rememberBarcodeScanner in a Frame Processor.
Parameters
The formats to scan for. To detect all kinds of barcodes, use listOf(TargetBarcodeFormat.ALL_FORMATS).
Which camera buffer resolution is used: BarcodeScannerOutputResolution.PREVIEW prefers preview-sized buffers for lower latency, BarcodeScannerOutputResolution.FULL full/highest available buffers for better detail.
Called whenever barcodes have been detected.
Called when there was an error detecting barcodes.