Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extractThumbnail generate unknown bitmap configuration error

I'm trying to generate a thumbnail form an image resource, using the method:

ThumbnailUtils.extractThumbnail(Bitmap src, int width, int height);

But when I do so, I get the error:

java.lang.IllegalArgumentException: unknown bitmap configuration

Here is my code:

// get a scaled down version of the image resource, to avoid loading
// the full image into memory
Bitmap im1 = decodeSampledBitmapFromResource(context.getResources(),
                R.drawable.im1, 
                R.dimen.thumbnail_width,
                R.dimen.thumbnail_height);

Bitmap thumbnail = ThumbnailUtils.extractThumbnail(im1,
                     R.dimen.thumbnail_width,
                     R.dimen.thumbnail_height);

holder.picture.setImageBitmap(thumbnail);

The error pops at the line where the method extractThumbnail is called.

The method decodeSampledBitmapFromResource is the one described here: https://developer.android.com/intl/es/training/displaying-bitmaps/load-bitmap.html

The image is a "JPEG" image of size 680x1024, weighting 183Ko.

I have tried to use instead the method:

Bitmap.createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter);

But I get the same error.

like image 758
JeromeB Avatar asked Dec 28 '25 04:12

JeromeB


1 Answers

You may be having issues because you are passing in the id's of your resources instead of the actual values those id's represent. Try adding

int height = (int)context.getResources().getDimension(R.dimen.thumbnail_height);
int width = (int)context.getResources().getDimension(R.dimen.thumbnail_width);

and now modify your code to read like this.

// get a scaled down version of the image resource, to avoid loading
// the full image into memory
Bitmap im1 = decodeSampledBitmapFromResource(context.getResources(),
                R.drawable.im1, 
                width,
                height);

Bitmap thumbnail = ThumbnailUtils.extractThumbnail(im1,
                     width,
                     height);
like image 173
phxhawke Avatar answered Dec 30 '25 20:12

phxhawke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!