1

I am trying to decode Base64 string image to Bitmap, but it always returns null.

Here is my code:

 public static Bitmap getBitmap(String encode) {

        Bitmap bm = null;
        try { 
            byte[] decodedString = Base64.decode(encode, Base64.DEFAULT);
            bm = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

        } catch (Exception e) { 
            Log.e(TAG,e.getMessage());
            return bm;
        }

        return bm;
    }
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • 2
    post your code it will be helpful – shyam Sep 15 '18 at 11:11
  • Here is my code to: public static Bitmap getBitmap(String encode) { Bitmap bm = null; try { byte[] decodedString = Base64.decode(encode, Base64.DEFAULT); bm = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); } catch (Exception e) { Log.e(TAG,e.getMessage()); return bm; } return bm; } – SanderPatrick Sep 15 '18 at 11:14

1 Answers1

0

For me this code works:

Bitmap bmp = BitmapFactory.decodeByteArray(Base64.decode(B64.BASEFILE, Base64.DEFAULT), 0, Base64.decode(B64.BASEFILE, Base64.DEFAULT).length);
ImageView iw = findViewById(R.id.imageView);
iw.setImageBitmap(bmp);

I'm compiling this on API 22.

Xyz
  • 212
  • 2
  • 9