我有一个在图像上的XML for Pinch Zoom功能中定义Activity的自ImageView定义.现在,我的问题是我想Bitmap从Pinch Zoom功能中获取缩放比例.例如,如果用户对图像进行缩放,那么我想将图像的确切大小和位置存储为位图.
这是我在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"
/>
Run Code Online (Sandbox Code Playgroud)
更新:
我正在尝试下面的代码来获取缩放的图像,但它返回一个空白位图.
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);
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.谢谢
Lal*_*ani 12
好吧,最后我无法相信这只是一行代码.我终于成功使用了matrix.解决方案非常简单,我translation and scaling将图像存储在矩阵中.所以,我宣布最终matrix为public static和使用该矩阵在画布上创建绘制Bitmap.
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);
Run Code Online (Sandbox Code Playgroud)
正如你在这里看到的那样PinchZoom_ImageView.matrix.这是一个matrix包含我声明的缩放和翻译图像的最终位置public static.
| 归档时间: |
|
| 查看次数: |
4710 次 |
| 最近记录: |