Getting started¶
Add the dependency¶
kotlin {
sourceSets {
commonMain.dependencies {
implementation("io.github.yuroyami:kiteqr:0.1.0")
// optional, for drawing onto Compose surfaces:
// implementation("io.github.yuroyami:kiteqr-compose:0.1.0")
}
}
}
The core has a single transitive dependency, kotlin-stdlib. It also works in a
plain Android or JVM project. Add it to your normal dependencies { } block.
Generate a QR code¶
import io.github.yuroyami.kiteqr.Qr
import io.github.yuroyami.kiteqr.qrcode.decoder.ErrorCorrectionLevel
import io.github.yuroyami.kiteqr.render.toPng
import io.github.yuroyami.kiteqr.render.toSvg
val matrix = Qr.encode(
contents = "WIFI:T:WPA;S:MyNetwork;P:hunter2;;",
ecLevel = ErrorCorrectionLevel.Q,
)
val svg: String = matrix.toSvg() // vector
val png: ByteArray = matrix.toPng(scale = 8) // raster bytes
toSvg and toPng are extensions in io.github.yuroyami.kiteqr.render. That
is a different package from Qr, so they need their own imports.
Scan a QR code¶
Feed the decoder a LuminanceSource. From a packed ARGB image:
import io.github.yuroyami.kiteqr.Qr
import io.github.yuroyami.kiteqr.RGBLuminanceSource
val text: String? = Qr.decode(RGBLuminanceSource(width, height, argbPixels)).getText()
println(text)
Result.getText() returns String?, not String.
From a camera frame (YUV), use PlanarYUVLuminanceSource. To scan every
supported barcode format at once, use the multi-format reader instead of Qr.
Next¶
- Generating codes: modes, ECI charsets, versions, masks.
- Rendering: SVG and PNG options, colors, quiet zone.
- Compose binding: the
QrCodecomposable.