我有一个Activity,它在XML中定义了一个定制的ImageView,用于压缩图像上的缩放功能。现在,我的问题是,我想从压缩缩放功能中获取缩放的Bitmap。例如,如果用户peform在图像上缩放,那么我希望存储图像的确切大小和位图的位置。
这是我用XML声明的自定义ImageView。
<com.cam.view.PinchZoom_ImageView
android:id="@+id/gallery_selected_image_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/icon"
android:scaleType="center"
/>更新:
我正在尝试下面的代码来获取缩放图像,但它返回一个空白位图。
pinchZoom.setDrawingCacheEnabled(true);
pinchZoom.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
pinchZoom.layout(0, 0, pinchZoom.getMeasuredWidth(), pinchZoom.getMeasuredHeight());
pinchZoom.buildDrawingCache(true);
Bitmap_gallery_Item = Bitmap.createBitmap(pinchZoom.getDrawingCache());
pinchZoom.setDrawingCacheEnabled(false);任何帮助都将不胜感激。谢谢
发布于 2011-10-05 09:14:00
最后我真不敢相信那只是一行代码。我终于成功地使用了matrix。解决方案非常简单,我将图像的translation and scaling存储在一个矩阵中。因此,我将最终的matrix声明为public static,并使用这个矩阵在画布上创建一个位图。
Canvas comboImage = new Canvas(cs);
background = Bitmap.createScaledBitmap(background, width, height, true);
comboImage.drawBitmap(background, 0, 0, null);
comboImage.drawBitmap(foreground, PinchZoom_ImageView.matrix, null);正如你在这里看到的,PinchZoom_ImageView.matrix。这是一个matrix,它包含了我的缩放和翻译图像的最后位置,我已经声明为public static。
发布于 2011-10-04 12:59:46
如果您有scaleType="fitxy",那么您可以使用缩放因子来放大或缩小ImageView的宽度/高度--这也意味着您可以拉回图像的确切高度/宽度,因为它与容器的尺寸相同。
HTH
发布于 2011-10-04 15:47:28
这篇文章包括从图片库中剪切图像,并允许用户裁剪图像并保存裁剪后的图像和ImageView中的显示。
似乎它会帮你一些扩展
图像裁剪并在视图中显示裁剪后的图像
https://stackoverflow.com/questions/7648155
复制相似问题