1

I'm receiving a Base64 encoded string in my Android app, and converting it to a bitmap as follows:

final String base64Image = getPicResponse.getString(GETPIC_PARAM_BASE64IMAGE);

final byte[] decodedString = Base64.decode(base64Image, Base64.DEFAULT);

Bitmap decodedByteBitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

Sometimes decodedByteBitmap is a valid bitmap, sometimes it's null. When trying to find a pattern I print the following:

DataUtils.log("In GcmIntentService - Received image length is: " + base64Image.length());

and when using 2 test images, I noticed it fails when the string is longer. For example, it will work for a string length of 465,072, but will fail for a string length of 672,412.

Does the BitmapFactory.decodeByteArray have a input size limit I'm not aware of? If so, what other ways can I convert a Base64 encoded bitmap into a bitmap?

The docs (http://developer.android.com/reference/android/graphics/BitmapFactory.html) only mention it returns null if it can't be decoded, but don't give any other information.

Thanks

zundi
  • 2,361
  • 1
  • 28
  • 45
  • See if you can break it down. First pull the image into a byte[] or even better, stick it on disk and open an input stream to it. Then find a method that will convert an inputStream into the bitmap for you. Here's an example [link] (http://stackoverflow.com/questions/6612263/converting-input-stream-into-bitmap) – Justin Tamblyn Jan 26 '16 at 06:30
  • @Harshad which answer? – zundi Feb 06 '16 at 02:31

0 Answers0