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