Reputation: 91
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?
Upvotes: 9
Views: 8958
Reputation: 10203
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);
Upvotes: 18
Reputation: 1615
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!
Upvotes: 5
Reputation: 3380
Place your images in a folder called "drawable" (without the ldpi, mdpi, hdpi et. al. suffix). You may probably need to create it by yourself (Eclipse for example, doesn't create this automatically).
After that, delete the drawable resource from your other drawable-something folders.
Upvotes: -1
Reputation: 9117
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.
Upvotes: 1