Skip to content

Instantly share code, notes, and snippets.

View SherifMuSherif's full-sized avatar

Sherif Sherif SherifMuSherif

  • Vancouver, BC
View GitHub Profile
@SherifMuSherif
SherifMuSherif / QRPainter.kt
Last active January 28, 2024 06:52 — forked from dev-niiaddy/QRPainter.kt
A function to encode text as a QR code using BitmapPainter and zxing-core for use in Jetpack Compose with Image composable. Note: This function has been optimized to set all pixels at once using setPixels, which significantly improves performance, especially when used in a LazyColumn. Thanks @dev-niiaddy!
@Composable
fun rememberQrBitmapPainter(
content: String,
size: Dp = 150.dp,
padding: Dp = 0.dp
): BitmapPainter {
val density = LocalDensity.current
val sizePx = with(density) { size.roundToPx() }
val paddingPx = with(density) { padding.roundToPx() }