0

I have a an image image.png in the drawable folder (not any of the other drawable-hdpi, etc. folders).

This image's size is 50x50. But when I load it from my application like so: BitmapFactory.decodeResource(getResources(), R.drawable.image)

and then I check the size with getWidth() and getHeight(), I get 150x150.

Can anyone please explain how to calculate this 150x150 loaded size? (Not programmatically, I just want to know if there's a formula I could have used to tell that the image would be loaded to 150x150)

Also, is this 150x150 in pixels?

Thanks!

Rajesh Jadav
  • 12,801
  • 5
  • 53
  • 78
Stralo
  • 474
  • 4
  • 16

3 Answers3

1
  • Yes, the value is in pixel unit, make use of the java doc my friend~
  • If you want the image size to stay unchanged, put it into drawable-nodpi
  • If you put the image in the drawable, it is the same as in the drawable-mdpi, as the first Android-powered device, the T-Mobile G1 is a normal size and mdpi (medium) density :)
  • And the no magic formula :

    ldpi (low) ~120dpi
    mdpi (medium) ~160dpi
    hdpi (high) ~240dpi
    xhdpi (extra-high) ~320dpi
    xxhdpi (extra-extra-high) ~480dpi
    xxxhdpi (extra-extra-extra-high) ~640dpi

    That is, in your case, likely developing on a xxhdpi device, 480/160*50=150, remember android is designed to be visualize all the ui elements at the same size on all screens, so the higher density , the larger scaled image .

Neil
  • 664
  • 6
  • 16
0

If you have Drawable image and you want to calculate the size of a loaded image

Drawable d = getResources().getDrawable(R.drawable.image);
int h = d.getIntrinsicHeight(); 
int w = d.getIntrinsicWidth();  

Android Documentation says:

public int getIntrinsicHeight ()

Return the intrinsic height of the underlying drawable object. Returns -1 if it has no intrinsic height, such as with a solid color.

public int getIntrinsicWidth ()

Return the intrinsic width of the underlying drawable object.Returns -1 if it has no intrinsic width, such as with a solid color.

Rajesh Jadav
  • 12,801
  • 5
  • 53
  • 78
0

in android studio we use image size like this combinations.

Android
  • 535
  • 5
  • 16