Franziskus Karsunke Franziskus Karsunke -4 years ago 66
Android Question

BitmapFactory returns bigger image than source

Hi i am creating a Bitmap from an png image named

. The image has the dimension 75 (width) x 92 (height). When I run this code:

Bitmap bitmap = BitmapFactory.decodeResource(this.context.getResources(), R.drawable.image
Log.d("image", "height: " + bitmap.getHeight() + " width: " + bitmap.getWidth());

the logger logs:

DEBUG/image(3550): height: 138 width: 113

and the image on the screen is bigger than other images which have the dimension 75 x 92. What can I do to make android load the image with the right dimension?

Answer Source

It sounds like your screen density on your device is different than the density where image.png was created.

If you really want to prevent the scaling, you could try one of the following:

  1. Put the image in res/drawable-nodpi (

  2. Use ImageView.ScaleType.CENTER (

  3. Just found this related question on SO: Android: How to stop Android 1.6+ from scaling images

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download