get bitmap from visible zoomed image android

后端 未结 1 1321
情深已故
情深已故 2021-02-04 15:29

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

相关标签:
1条回答
  • 2021-02-04 15:55

    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.

    0 讨论(0)
提交回复
热议问题