【发布时间】:2013-02-14 05:04:08
【问题描述】:
我有一个图像视图
<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
在此之后,我在上面的图像视图中将此位图显示为imgCaptured.setImageBitmap(thumbnail);,然后我将图像视图的大小设为
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 分辨率保存此图像。有可能吗?
提前致谢。
【问题讨论】:
-
澄清一下-您的意思是图像视图中位图的大小?如果没有padding,两者是等价的,ImageView的宽/高就是位图的宽/高。如果您有填充,只需将其减去。
-
是的,我的意思是位图在图像视图中显示后的大小。
-
@Gabe Sechan 实际上我已经捕获了 2592x1936 的图像。我在我的 imageView 中显示了这张图片,对这张图片做了一些其他的操作。现在我想以相同的 2592x1936 分辨率保存此图像。有可能吗?
-
是的,但可能质量不高。如果缩小图像(不保留完整大小的版本),则在缩小图像时会丢失数据,Android 会在扩展图像时猜测数据是什么。如果您操作的是完整大小的版本,则相当简单——只需使用带有 FileOutputStream 的位图类上的 compress() 函数。
-
感谢回复您能否粘贴代码,用于从 2592x1936 大小的图像视图中检索全尺寸图像。
标签: android bitmap imageview android-imageview bitmapimage