9

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?

Sunny
  • 91
  • 1
  • 3
  • 1
    After second round of Goggling, I find out there is a folder called "drawable-nodpi". Therefore the problem seems solved. – Sunny Jul 24 '11 at 10:35

4 Answers4

18

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);
Dmitry Zaytsev
  • 23,650
  • 14
  • 92
  • 146
XGouchet
  • 10,002
  • 10
  • 48
  • 83
  • 1
    You need to add the options into the load isntruction: Bitmap bitmap = BitmapFactory.decodeResource(ctx.getResources(), R.id.mybmp, opts); – Tickled Pink Sep 09 '12 at 14:15
5

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!

Zwiebel
  • 1,605
  • 4
  • 21
  • 37
1

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.

Kumar Bibek
  • 9,016
  • 2
  • 39
  • 68
-1

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.

Vicente Plata
  • 3,370
  • 1
  • 19
  • 26