BimapFactory generates bitmap to load, but after loading, it will always return empty. Do you think it is amazing? In fact, the Android side needs to remove the returndata:image/jpeg; base64,This header will succeed. Here is a comparison of the wrong method and the right method

## Wrong way

funString? .covertBase64ToBitmap(a) : Bitmap? {
    if (this.isNullOrEmpty()) return null
    val qrByteArray = Base64.decode(this, Base64.NO_WRAP)
    return BitmapFactory.decodeByteArray(qrByteArray, 0, qrByteArray.size)
}
Copy the code

——————– VS ——————–

## The right way

funString? .covertBase64ToBitmap(a) : Bitmap? {
    if (this.isNullOrEmpty()) return null
    val qrStr = if (this.contains("data:image/jpeg; base64,")) {
        this.replace("data:image/jpeg; base64,"."")}else {
        this
    }
    val qrByteArray = Base64.decode(qrStr, Base64.NO_WRAP)
    return BitmapFactory.decodeByteArray(qrByteArray, 0, qrByteArray.size)
}
Copy the code

If it works for you, thanks for the “like”.