Skip to content

Scanning and decoding

Decoding works from any LuminanceSource. KiteQR ships several:

  • RGBLuminanceSource(width, height, argbPixels) takes a still image, an IntArray of ARGB.
  • PlanarYUVLuminanceSource(...) takes camera preview frames (YUV), with cropping.
  • GrayscaleLuminanceSource(...) takes luminance bytes you already have.
  • InvertedLuminanceSource(...) wraps another source and flips its luminance.
  • LuminanceSource is an abstract class. Subclass it for anything else.

A single QR

import io.github.yuroyami.kiteqr.Qr
import io.github.yuroyami.kiteqr.RGBLuminanceSource

val result = Qr.decode(RGBLuminanceSource(width, height, argb))
println(result.getText())

Qr.decode wraps the source in a HybridBinarizer and runs the QR reader with TRY_HARDER. It throws NotFoundException if nothing is found.

Other barcode formats

import io.github.yuroyami.kiteqr.BinaryBitmap
import io.github.yuroyami.kiteqr.MultiFormatReader
import io.github.yuroyami.kiteqr.common.HybridBinarizer

val bitmap = BinaryBitmap(HybridBinarizer(source))
val result = MultiFormatReader().decode(bitmap)
println("${result.getBarcodeFormat()}: ${result.getText()}")

To restrict which formats are tried (faster), pass DecodeHintType.POSSIBLE_FORMATS. For several codes in one image, use GenericMultipleBarcodeReader or, for QR, QRCodeMultiReader.

Structured results

ResultParser.parseResult(result) turns a decoded string into a typed ParsedResult: URL, Wi-Fi, vCard, geo, calendar event, email, SMS, product code, and more.

Calendar events written in local time (no trailing Z) are interpreted as UTC, because common Kotlin has no host timezone. See Differences from ZXing.