Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I don't want Android to resize my bitmap Automatically

I have placed some bitmaps in res/drawable.

After I load the bitmaps by BitmapFactory.decodeResource(), I find out that they are resized automatically according the density.

This is not what I want. I want them to keep their original size (pixel size).

What should I do?

like image 562
Sunny Avatar asked Jul 24 '11 06:07

Sunny


3 Answers

As was said in another question, using the drawable-nodpi folder will prevent android from resizing your pictures.

Additionally, if you want to have multiple versions of an image for hdpi and ldpi format, but don't want the system to resize them (to keep a power of two resolution for example), you can use the following code while loading your bitmpap :

// ask the bitmap factory not to scale the loaded bitmaps
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScaled = false;

// load the bitmap
Bitmap bitmap = BitmapFactory.decodeResource(ctx.getResources(), R.id.mybmp, opts);
like image 98
XGouchet Avatar answered Sep 23 '22 17:09

XGouchet


http://developer.android.com/guide/practices/screens_support.html

If you use the nodpi suffix, the system won't scale your pictures automatic. Hope it helps!

like image 20
Zwiebel Avatar answered Sep 23 '22 17:09

Zwiebel


If you have kept separate images in your hdpi, ldpi, and mdpi, and you are using resources to access these images, then you can't do much.

If you just want one image to be used, keep a single copy of it in mdpi folder, and delete the others.

like image 31
Kumar Bibek Avatar answered Sep 21 '22 17:09

Kumar Bibek