从可见的缩放图像android获取位图 [英] get bitmap from visible zoomed image android

查看:86
本文介绍了从可见的缩放图像android获取位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Imageview,它可以缩放和旋转(我用过multitouch zooming).因此,如何获得仅可见内容的位图(我的意思是当缩放image时,位图的一部分可能会超出屏幕.所以,我想要的是在屏幕上可见的bitmap) .那么api中是否有任何内置功能可以从一个大的位图创建一个小位图?或是否有使用x,y坐标裁剪图像的功能?实际上,我希望缩放或旋转的部分转到下一个activity

I have an Imageview which is zoomed and rotated(I have used multitouch zooming). So how can i get bitmap of only visible content(I mean when i zoom the image, The part of the bitmap may go out of the screen. So, what i want is the bitmap that is visible on the screen). So is there any built in feature in api to create a small bitmap from a big one? or Is there any function to crop the image using x,y coordinates? actually i want the zoomed or rotated part to go to the next activity

推荐答案

如果您知道所有比例和旋转值,则可以创建

If you know all the scale and rotation-values, you can create a Matrix with those values, and apply them to your bitmap via the Bitmap.createBitmap() method.
Example:

Bitmap original = ((BitmapDrawable) yourImageView.getDrawable()).getBitmap();
Matrix matrix = new Matrix();
matrix.setRotate(degrees);
matrix.postScale(scale, scale);
Bitmap result = Bitmap.createBitmap(original, 0, 0, original.getWidth(), original.getHeight(), matrix, true);

一种更快但可能不是很漂亮的解决方案是创建一个位图并将您当前可见的视图绘制到该位图上:

A faster, but maybe not as pretty solution is to create a bitmap and draw your currently visible view onto that:

Bitmap result = Bitmap.createBitmap(yourImageView.getWidth(), yourImageView.getHeight(), Bitmap.Config.RGB_565);
Canvas c = new Canvas(result);
yourImageView.draw(c);

此后的结果应完全包含您在屏幕上看到的内容.

After which result should contain exactly what you see on screen.

这篇关于从可见的缩放图像android获取位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆