BitmapFactory returns a larger image than the source

Hi, I am creating a bitmap from a png image called image.png . Image is 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()); 

log magazines:

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

and the image on the screen is larger than other images with a size of 75 x 92. What can be done to get the Android to download the image with the correct size?

+7
source share
3 answers

It looks like the density of your screen on your device is different from the density where image.png was created.

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

+11
source

My decision:

 BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false; Bitmap bitmap = BitmapFactory.decodeResource(this.context.getResources(), R.drawable.image, options ); 
+18
source

The Beause loader in BitmapFactory applies scaling to screen density at boot time. To override this, provide your own desired inTargetDensity in BitmapFactory.Options in the call to decodeResource.

+3
source

All Articles