mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 17:35:54 +03:00
Improve code
This commit is contained in:
parent
c323b61575
commit
d2fab91e9d
2 changed files with 12 additions and 7 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/itemVerificationBigImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="180dp"
|
||||
android:layout_margin="8dp"
|
||||
android:src="@drawable/ic_shield_trusted" />
|
||||
tools:src="@drawable/ic_shield_trusted" />
|
||||
|
|
Loading…
Reference in a new issue