Android
The Image Scanner SDK decodes QR codes and Cronto images from CameraX frames (ImageProxy) or from bitmaps.
Exposed APIs
For Android, the Image Scanner SDK APIs are exposed in the com.vasco.digipass.sdk.utils.qrcodescanner package. For detailed information about the APIs and SDK functions, refer to the technical documentation included in the product package.
Code types
Both decoding methods are static methods on QRCodeScannerSDK. They take a codeType bitmask that specifies which codes to look for:
| Searches for |
|---|---|
| QR codes |
| Cronto images |
| Either (Cronto is tried first and, if not found, QR code is tried next.) |
CameraX-Based Decoding Method (CameraX ImageAnalysis)
The following method decodes a QR code or Cronto image from a CameraX frame. Use decodeImage inside an ImageAnalysis.Analyzer. The accepted formats are YUV_420_888 and RGBA_8888. Choose the output format based on the code type you are scanning:
Scanning for | Recommended output format |
|---|---|
QR codes only |
|
Cronto images only |
|
The recommended format avoids an extra conversion step and makes decoding faster:
val cameraExecutor = Executors.newSingleThreadExecutor()
val imageAnalysis = ImageAnalysis.Builder()
.setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_YUV_420_888)
.build()
.also { it.setAnalyzer(cameraExecutor, CodeAnalyzer()) }
class CodeAnalyzer : ImageAnalysis.Analyzer {
override fun analyze(image: ImageProxy) {
try {
val result = QRCodeScannerSDK.decodeImage(
image,
QRCodeScannerSDKConstants.QR_CODE + QRCodeScannerSDKConstants.CRONTO_CODE
)
result.scannedImageData?.let { data ->
// Code found: result.scannedImageFormat is QR_CODE or CRONTO_CODE
}
} catch (e: QRCodeScannerSDKException) {
// See Error Handling below
} finally {
image.close() // Required, otherwise the camera stops delivering frames
}
}
}Bind imageAnalysis to the lifecycle together with your Preview use case, using ProcessCameraProvider.bindToLifecycle.
Bitmap Decoding Method
The following method decodes an image containing a Cronto image or QR code from a bitmap such as an image from the device gallery. Use decodeBitmap for static images.
val result = QRCodeScannerSDK.decodeBitmap(
bitmap,
QRCodeScannerSDKConstants.QR_CODE + QRCodeScannerSDKConstants.CRONTO_CODE
)The bitmap must be in ARGB_8888 format.
When loading photos from the gallery:
Downsample large photos
(For example with
BitmapFactory.Options.inSampleSize.) Full-resolution camera photos are slow to decode, use a lot of memory, and can cause out of memory (OOM) errors.Decode in sRGB.
The decoding of Cronto images relies on color, and wide-gamut photos (e.g. Display P3) shift the colors the SDK reads. On API 26+, set
inPreferredColorSpace = ColorSpace.get(ColorSpace.Named.SRGB).
val options = BitmapFactory.Options().apply {
inPreferredConfig = Bitmap.Config.ARGB_8888
inSampleSize = sampleSize
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
inPreferredColorSpace = ColorSpace.get(ColorSpace.Named.SRGB)
}
}
val bitmap = contentResolver.openInputStream(uri)?.use {
BitmapFactory.decodeStream(it, null, options)
}Obtain Decoding Results
Both decoding methods return a QRCodeScannerSDKDecodingResultData:
scannedImageData: String?returns the decoded content, ornullif no code was found.scannedImageFormat: IntreturnsQR_CODE,CRONTO_CODE, or-1if no code was found.
Decoding is CPU-intensive. Always call these methods off the main thread.
Java
The API works in the same manner from Java:
QRCodeScannerSDK.QRCodeScannerSDKDecodingResultData result =
QRCodeScannerSDK.decodeImage(image, QRCodeScannerSDKConstants.QR_CODE);
String data = result.getScannedImageData();iOS
On iOS, the SDK supports the following primary use cases:
Scan and decode a QR code or Cronto image from a single image with the
decodeImagemethodReal-time decoding of QR codes and Cronto images by integrating the SDK with an
AVCaptureSession; this is enabled with theconfigureAndBindSessionmethod.