n83
n83

Reputation: 237

android.renderscript.RSInvalidStateException: Bad bitmap type: null

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);

Upvotes: 0

Views: 1514

Answers (1)

Tim Murray
Tim Murray

Reputation: 2205

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.

Upvotes: 1

Related Questions