Answers for "generate qr code kotlin"

1

qr code generation function kotlin

//Code
private fun generateQRCode(text: String): Bitmap {
    val width = 500
    val height = 500
    val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
    val codeWriter = MultiFormatWriter()
    try {
        val bitMatrix = codeWriter.encode(text, BarcodeFormat.QR_CODE, width, height)
        for (x in 0 until width) {
            for (y in 0 until height) {
                bitmap.setPixel(x, y, if (bitMatrix[x, y]) Color.BLACK else Color.WHITE)
            }
        }
    } catch (e: WriterException) {
        Log.d(TAG, "generateQRCode: ${e.message}")
    }
    return bitmap
}
Posted by: Guest on February-17-2021
1

qr code generation function kotlin

//Usage
val bitmap = generateQRCode("Sample Text")
imageView.setImageBitmap(bitmap)
Posted by: Guest on February-17-2021

Code answers related to "generate qr code kotlin"

Browse Popular Code Answers by Language