get bitmap from visible zoomed image android

别来无恙 提交于 2020-01-12 03:30:08

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/8490870/get-bitmap-from-visible-zoomed-image-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!