Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从ImageView获取缩放位图_Android - Fatal编程技术网

Android 如何从ImageView获取缩放位图

Android 如何从ImageView获取缩放位图,android,Android,我有一个活动,它在XML中定义了一个自定义图像视图,用于图像上的收缩缩放功能。现在,我的问题是我想从收缩缩放功能中获取缩放的位图。例如,如果用户对图像进行缩放,则我希望将图像的确切大小和位置存储为位图 这是我用XML声明的自定义ImageView <com.cam.view.PinchZoom_ImageView android:id="@+id/gallery_selected_image_view" android:layout_width="fill_parent" a

我有一个
活动
,它在XML中定义了一个自定义
图像视图
,用于图像上的收缩缩放功能。现在,我的问题是我想从收缩缩放功能中获取缩放的
位图。例如,如果用户对图像进行缩放,则我希望将图像的确切大小和位置存储为位图

这是我用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"
 />

任何帮助都将不胜感激。谢谢

如果您有
scaleType=“fitxy”
,那么您可以使用缩放因子放大或缩小图像视图的宽度/高度-这也意味着您可以拉回图像的精确高度/宽度,因为它与容器的尺寸相同


HTH

这篇文章包括从图库中裁剪图像,允许用户裁剪图像并保存裁剪后的图像,并在ImageView中显示

看来这对你有帮助


嗯,最后我真不敢相信它只是一行代码。我终于成功地使用了
矩阵
。解决方案非常简单,我将图像的
平移和缩放
存储在矩阵中。所以,我将final
matrix
声明为
publicstatic
,并使用该矩阵在画布上创建并绘制位图

        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\u ImageView.matrix
。它是一个
矩阵
,包含缩放和翻译图像的最终位置,我已声明为
公共静态

我没有fitxy buddy,我的图像是可移动的,还允许缩放,因此我希望在翻译和缩放图像后存储位图。ThanksOk-我不知道情况是什么,但是你不能通过实现上面的ImageView来移动和缩放图像吗?通过上面的方法,你是说通过使用scaleType=“fitxy”?是的,通过使用ImageView作为图像。好的,我想这是有原因的,不建议只是改变它:)@Lalit Poptani Okay damachan@LalitPoptani-看起来只有在显式设置ImageView矩阵的情况下才有效。如果有一种方法,无论缩放类型如何,都能提取当前显示的位图,那将是一件很棒的事情。
        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);