如何获得图像的宽度和高度?

时间:2022-11-19 13:11:06

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 ?

我想得到我存储在drawable文件夹中的图像的宽度和高度。这可能吗,如果有,请告诉我?

2 个解决方案

#1


61  

try

BitmapDrawable bd=(BitmapDrawable) this.getResources().getDrawable(R.drawable.icon);
int height=bd.getBitmap().getHeight();
int width=bd.getBitmap().getWidth();

#2


16  

I have follow this link :-

我关注此链接: -

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

#1


61  

try

BitmapDrawable bd=(BitmapDrawable) this.getResources().getDrawable(R.drawable.icon);
int height=bd.getBitmap().getHeight();
int width=bd.getBitmap().getWidth();

#2


16  

I have follow this link :-

我关注此链接: -

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