How to get width and height of the image?
37,542
Solution 1
try
BitmapDrawable bd=(BitmapDrawable) this.getResources().getDrawable(R.drawable.icon);
int height=bd.getBitmap().getHeight();
int width=bd.getBitmap().getWidth();
Solution 2
I have follow this link :-
Drawable d = getResources().getDrawable(R.drawable.yourimage);
int h = d.getIntrinsicHeight();
int w = d.getIntrinsicWidth();
Related videos on Youtube
Author by
ramsbh
Updated on May 13, 2022Comments
-
ramsbh 15 days
HI,
I want to get width and height of the image which i was stored in the drawable folder. Is this possible, if so please let me know ?
-
SBotirov about 7 yearsThis is very good answer, i used this answer to set same with message status ImageView[one checked icon, two checked icon] : stackoverflow.com/questions/9655534/…
-
-
hackbod over 11 yearsI would prefer to do this without casts, by using Drawable.getIntrinsicWidth/Height().
-
Avisek Chakraborty over 10 yearsusing the above code, getting two-third of the original size. For e.g- an image has 644 X 550 dimension; but am getting- 429 X 367 from code. What may be the issue?
-
David T. over 9 yearsdo you have multiple density folders? hdpi and mdpi? sounds like BitmapDrawable is getting confused with which one to pick. set the right density in the Options, like developer.android.com/reference/android/graphics/…
-
Navid over 7 yearsthis is more applicable for me, because gives you the size of View independent of weather it is shown on screen or not!
-
Sanket990 almost 7 yearsgetDrawable method is deprected . which method used instead of "getDrawable" method
-
GeordieMatt about 6 yearsThe non-deprecated version of getDrawable is ResourcesCompat.getDrawable, which supports themes. If you don't need a theme, just pass null into it (docs here: developer.android.com/reference/android/support/v4/content/res/…).