diff --git a/vector/src/main/java/im/vector/riotx/core/qrcode/QrCode.kt b/vector/src/main/java/im/vector/riotx/core/qrcode/QrCode.kt index a4e7ee2e07..0af2cf6777 100644 --- a/vector/src/main/java/im/vector/riotx/core/qrcode/QrCode.kt +++ b/vector/src/main/java/im/vector/riotx/core/qrcode/QrCode.kt @@ -18,27 +18,31 @@ package im.vector.riotx.core.qrcode import android.graphics.Bitmap import android.graphics.Color +import androidx.annotation.ColorInt import com.google.zxing.BarcodeFormat import com.google.zxing.common.BitMatrix import com.google.zxing.qrcode.QRCodeWriter -fun String.toQrCode(width: Int = 200, - height: Int = 200): Bitmap { +fun String.toQrCode(width: Int, + height: Int, + @ColorInt backgroundColor: Int = Color.WHITE, + @ColorInt foregroundColor: Int = Color.BLACK): Bitmap { return QRCodeWriter().encode( this, BarcodeFormat.QR_CODE, width, height - ).toBitmap() + ).toBitmap(backgroundColor, foregroundColor) } -fun BitMatrix.toBitmap(): Bitmap { +fun BitMatrix.toBitmap(@ColorInt backgroundColor: Int = Color.WHITE, + @ColorInt foregroundColor: Int = Color.BLACK): Bitmap { val height: Int = height val width: Int = width - val bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565) + val bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) for (x in 0 until width) { for (y in 0 until height) { - bmp.setPixel(x, y, if (get(x, y)) Color.BLACK else Color.WHITE) + bmp.setPixel(x, y, if (get(x, y)) foregroundColor else backgroundColor) } } diff --git a/vector/src/main/res/layout/item_verification_big_image.xml b/vector/src/main/res/layout/item_verification_big_image.xml index 9f33b6c03c..e4a0db917f 100644 --- a/vector/src/main/res/layout/item_verification_big_image.xml +++ b/vector/src/main/res/layout/item_verification_big_image.xml @@ -1,7 +1,8 @@ + tools:src="@drawable/ic_shield_trusted" />