如何在ImageView的显示它后得到的位图的大小 [英] How to get the size of bitmap after displaying it in ImageView

查看:146
本文介绍了如何在ImageView的显示它后得到的位图的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ImageView的

I have a imageview

<ImageView
        android:id="@+id/imgCaptured"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:src="@drawable/captured_image" />

我从相机拍摄的图像,转换该图像为位图。

I capture a image from camera, converted that image into bitmap.

Bitmap thumbnail;
thumbnail = MediaStore.Images.Media.getBitmap(getActivity()
                    .getContentResolver(), imageUri);

当我在上面的ImageView显示出来,像

when i get the resolution of this bitmap before displaying it in my above imageview, like

Log.i("ImageWidth = " + thumbnail.getWidth(), "ImageHeight = "
                + thumbnail.getHeight());

其返回我 ImageWidth = 2592 ImageHeight = 1936年

在这之后我在上面的ImageView为 imgCaptured.setImageBitmap(缩略图)显示此位图; 然后我去我的ImageView的大小为

after this i displayed this bitmap in my above imageview as imgCaptured.setImageBitmap(thumbnail); then i go size of my imageview as

Log.i("ImageView Width = " + imgCaptured.getWidth(),
                "ImageView Height = " + imgCaptured.getHeight());

这回我 ImageView的宽度= 480 ImageView的高度= 720

我现在的问题是,


  • 我怎样才能得到位图的尺寸后在我的ImageView显示它。
    我知道这可以通过使用这个来完成

  • How can i get the size of that bitmap after displaying it in my imageview. I know this can be done by using this

image.buildDrawingCache();
Bitmap bmap = image.getDrawingCache();

但是这将创建一个大小相等的ImageView的新位图。

but this will create a new bitmap of size equal to that of imageview.

我也想知道,是否在ImageView的显示出来后,自动调整图像。如果是的话那么有没有什么办法来显示ImageView的图像而不调整图像大小。

I also want to know that, Does image resized automatically after displaying it in the imageview. if yes then is there any way to display the image in imageview without resizing the image.

修改

其实我已抓获的2592x1936的图像。我在ImageView的显示这一形象,这个形象上的一些其他操作。现在我想保存相同2592x1936分辨率的这一形象。这可能吗?

Actually i have captured an image of 2592x1936. I displayed this image in my imageView, did some other operations on this image . now i want to save this image with same 2592x1936 resolution. is it possible?

先谢谢了。

推荐答案

在您显示在ImageView的一个位图,该ImageView的将创建一个BitmapDrawable对象绘制它的ImageView的画布。所以,你可以调用ImageView.getDrawable()方法来获取BitmapDrawable参考,并获得通过调用Drawable.getBounds的边界(矩形RECT)方法。通过边界,就可以计算出位图中的ImageView绘制的宽度和高度

After you display a Bitmap in a ImageView, The ImageView will create a BitmapDrawable object to draw it in ImageView's Canvas. So you can invoke ImageView.getDrawable() method to get the reference of the BitmapDrawable, and get the Bounds by invoke Drawable.getBounds(Rect rect) method. through the bounds, you can compute the width and height of the Bitmap drawn in ImageView

Drawable drawable = ImageView.getDrawable();
//you should call after the bitmap drawn
Rect bounds = drawable.getBounds();
int width = bounds.width();
int height = bounds.height();
int bitmapWidth = drawable.getIntrinsicWidth(); //this is the bitmap's width
int bitmapHeight = drawable.getIntrinsicHeight(); //this is the bitmap's height

这篇关于如何在ImageView的显示它后得到的位图的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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