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

Asked

Viewed 110 times

1

I 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 to say it has the same dimension as the original image. If my original image is in the res/drawable-mdpi folder and using the following code:

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

get hr = 552 and Wr=822, that is to say a 552x822 dimension and the image is 3 times larger than the original image. Why does this happen? Thank you

  • It would be possible to inform the URL of the image you are testing?

  • @Andréribeiro The URL used is this: http://alunos.deec.uc.pt/~a2008112913/image%20lida.jpg

  • This image is 274x184. It’s the original?

  • @Andréribeiro No, I put the original image in the res folder and got the width and height of the image using the following code: imageFromRes = Bitmapfactory.decodeResource(getResources(), R.drawable.imagem); int hr = imageFromRes.getHeight(); int Wr = imageFromRes.getWidth(); and I got a height of 552 and a width of 822... so I think these values are the correct ones of the original image. Thank you

  • I don’t understand. This link you sent is from the image generated or of original? I wanted to see the original image so I could test.

  • I downloaded the bitmap from the image URL, which is the same image I put in the res folder of my application. However in the bitmap obtained by download from the URL I got a dimension of 184x274 and in the bitmap obtained from the res folder using the code I put in the previous comment I got 552x822. The image in the res folder is the same image that is in this URL. Sorry if I didn’t make myself clear, I hope it is now explicit :) Thank you

  • Mark, edit your question and add this information. As it is written there it seems that your problem is quite another.

  • I’m sorry, I’ve already been able to confirm that the original image is 184x274! However using the code to load the bitmap, from the res folder the image is 552x822. But I don’t know why. Thanks I will edit.

Show 3 more comments

1 answer

3


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

To check the original image size you can do as follows:

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.