drawQRCode

fun <Error class: unknown class>.drawQRCode(qrCode: QRCode, offsetTopLeft: <Error class: unknown class> = Offset.Zero, sizeToFitInto: <Error class: unknown class> = this.size)(source)

Extension function to make it easier to draw a QRCode into a modern Jetpack Compose Canvas.

Usage example:

import qrcode.render.extensions.drawQRCode

@Composable
fun QRCodeKotlinQRCode(
text: String,
modifier: Modifier = Modifier,
) {
val qrCode = remember(text) {
QRCode.ofRoundedSquares()
.build(text)
}

Canvas(
modifier = modifier
.aspectRatio(1f)
) {
drawQRCode(qrCode) // Draw the QRCode at (0, 0)
}
}

Code sample by @dgmltn at GitHub, used with authors' permission and lightly modified :)

Original code: https://github.com/g0dkar/qrcode-kotlin/issues/141#issuecomment-2722041216

Parameters

qrCode

The QRCode that will be drawn into the DrawScope.

offsetTopLeft

The Offset of the top-left corner where the QRCode will be drawn. Defaults to Offset.Zero.

sizeToFitInto

The area in which to fit the QRCode. Defaults to the size of the DrawScope.