Why is the Bitmap bigger when loading it from the res / drawable-mdpi folder?

1

I've developed an application where I download a JPEG image (size 184x274) from a URL. When downloading from the URL I get a bitmap of 184x274 pixels, that is it has the same dimension as the original image. If my original image is in the res / drawable-mdpi folder and use the following code:

Bitmap imageFromRes;
imageFromRes = BitmapFactory.decodeResource(getResources(), R.drawable.imagem);
int hr = imageFromRes.getHeight();
int wr = imageFromRes.getWidth();

I get hr = 552 and wr = 822, that is a dimension of 552x822 and the image is 3 times larger than the original image. Why does it happen? Thanks

    
asked by anonymous 09.02.2015 / 14:25

1 answer

3

The dimensions returned on Android are proportional to the dpi of the device used.

To check the original size of the image you can do the following:

BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inScaled = false;
Bitmap imageFromRes = BitmapFactory.decodeResource(getResources(), R.drawable.imagem, opt);

With inScaled as false , the size returned is exactly the size of the image.

    
09.02.2015 / 16:18