0

I'm having difficulties loading an animated GIF via android.renderscript.Allocation. Here's the defective code:

Bitmap out = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);
mInAllocation = Allocation.createFromBitmap(mRS, src,
            Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);

It works fine on my Nexus 4 running Android 4.2 – but fails on my Optimus G running Android 4.1. The exception thrown is:

E/AndroidRuntime(8398): Caused by: android.renderscript.RSInvalidStateException: Bad bitmap type: null

That's being thrown from Allocation.typeFromBitmap because src.getConfig returns null; even though I specifically create it with the following code:

BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap photo = BitmapFactory.decodeByteArray(data, 0, data.length, bitmapOptions);
n83
  • 237
  • 2
  • 15

1 Answers1

1

ugh, this is a bug we found during 4.3 development and worked around (both in 4.3 and the support library). essentially, Bitmap.Config will return NULL for any indexed Bitmap. I don't know why 4.2 isn't failing, because I don't remember fixing that there (are you sure the N4 isn't on 4.3?).

the easiest way to work around it is, unsurprisingly: use the support lib if you can. it contains the fix.

Tim Murray
  • 2,205
  • 13
  • 13
  • You're absolutely correct - I was running 4.3 on my Nexus 4 which wasn't failing. Thanks for the update. I'll use the support lib for now. – n83 Oct 21 '13 at 20:37