7

我有一个图像视图

<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" />

我从相机捕捉图像,将该图像转换为位图。

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

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

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

它让我回归ImageWidth = 2592 ImageHeight = 1936

在此之后,我在上面的 imageview 中显示了这个位图,imgCaptured.setImageBitmap(thumbnail); 然后我将 imageview 的大小设置为

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

这让我回来了ImageView Width = 480 ImageView Height = 720

现在我的问题是

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

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

    但这将创建一个大小等于 imageview 的新位图。

  • 我也想知道,图像在图像视图中显示后是否会自动调整大小。如果是,那么有什么方法可以在不调整图像大小的情况下在 imageview 中显示图像。

编辑

实际上我已经捕获了 2592x1936 的图像。我在我的 imageView 中显示了这张图片,对这张图片做了一些其他的操作。现在我想以相同的 2592x1936 分辨率保存此图像。是否可以?

提前致谢。

4

1 回答 1

11

Bitmap在 a中显示 a后ImageViewImageView会创建一个 BitmapDrawable 对象以在 ImageView 的 Canvas 中绘制它。因此,您可以调用ImageView.getDrawable()方法来获取 的引用,并通过调用) 方法BitmapDrawable获取边界。Drawable.getBounds(Rect rect通过边界,您可以计算绘制的位图的宽度和高度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
于 2013-02-28T05:59:09.257 回答