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

查看:30
本文介绍了在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);

当我在上面的图像视图中显示它之前获得该位图的分辨率时,例如

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

此后,我在上面的图像视图中将此位图显示为 imgCaptured.setImageBitmap(thumbnail); 然后我将图像视图的大小设置为

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 Width = 480 ImageView Height = 720

现在我的问题是

  • 如何在我的图像视图中显示该位图之后获得它的大小.我知道这可以通过使用它来完成

  • 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 中显示图像.

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 中显示 Bitmap 后,ImageView 将创建一个 BitmapDrawable 对象以在 ImageView 的 Canvas 中绘制它.所以你可以调用ImageView.getDrawable()方法来获取BitmapDrawable的引用,通过调用Drawable.getBounds(Rect rect)来获取Bounds>) 方法.通过bounds,可以计算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天全站免登陆