draw QRCode
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)
}
}
Content copied to clipboard
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
qr Code
The QRCode that will be drawn into the DrawScope.
offset Top Left
The Offset of the top-left corner where the QRCode will be drawn. Defaults to Offset.Zero.
size To Fit Into
The area in which to fit the QRCode. Defaults to the size
of the DrawScope.