My app reads several BASE64 encoded images one by one from DB. But for some images(<0.1%), it fails to load. The method, BitmapFactory.decodeByteArray() return null which means its invalid format. But when I created a separate app with hard-coded culprit image, it worked. Now I have one big app where the same image didn't work and in my test app it works. Can anyone tell me why in God's name this is happening? Here is my code:
byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
Bitmap setBMPPath = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
if (setBMPPath != null) {
qImage.setImageBitmap(setBMPPath);
}
Is there any other method that I can use to convert byte array to Bitmap?
You can try adding Base64.NO_WRAP:
byte[] decodeResponse = Base64.decode(base64Image, Base64.DEFAULT | Base64.NO_WRAP);
Bitmap bitmap = BitmapFactory.decodeByteArray(decodeResponse, 0, decodeResponse.length);
Hope this helps someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With