如何获得在Android中使用的图像的高度和宽度 [英] How to get height and width of a image used in android

查看:88
本文介绍了如何获得在Android中使用的图像的高度和宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得一个形象,是无论在ImageView的还是Android的emulator.please背景图像帮助我,任何帮助将appriciated的高度和宽度。

I want to get height and width of a image that is either in ImageView or a background image in android emulator.please help me, any help will be appriciated.

推荐答案

您可以通过,而这不会给你图片的确切宽度和高度使用的getWidth()和getHeight()得到高度和宽度的ImageView的,对于第一次获得图像的宽度高度,你需要获得绘制背景,然后绘制转换为BitmapDrawable来获得图像从位图,你可以得到的宽度和高度喜欢这里

You can get height and width of ImageView by using getWidth() and getHeight() through while this will not give you the exact width and height of the image, for getting the Image width height first you need to get the drawable as background then convert drawable to BitmapDrawable to get the image as Bitmap from that you can get the width and height like here

Bitmap b = ((BitmapDrawable)imageView.getBackground()).getBitmap();
int w = b.getWidth();
int h = b.getHeight();

或不喜欢这里。

or do like here

imageView.setDrawingCacheEnabled(true);
Bitmap b = imageView.getDrawingCache();
int w = b.getWidth();
int h = b.getHeight();

以上code会给你当前的ImageView大小的位图就像截屏装置的

the above code will give you current imageview sized bitmap like screen shot of device

只有ImageView的大小

for only ImageView size

imageView.getWidth(); 
imageView.getHeight(); 

如果您有绘制的图像,并且希望的大小,你可以得到像这样

If you have drawable image and you want that size you can get like this way

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

这篇关于如何获得在Android中使用的图像的高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆