Answers for "qr code generation function kotlin"

1

qr code generation function kotlin

//Usage
val bitmap = generateQRCode("Sample Text")
imageView.setImageBitmap(bitmap)
Posted by: Guest on February-17-2021
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

//Dependency
implementation 'com.google.zxing:core:3.4.0'
Posted by: Guest on February-17-2021

Browse Popular Code Answers by Language