0

I use PhotoView library: https://github.com/chrisbanes/PhotoView

This is my initial case; it's the PhotoView component (red square); the background is transparent. I load a standard picture inside.

enter image description here

Now, I want to extract the visible bitmap part to another bitmap:

Bitmap original = mPhotoView.getVisibleRectangleBitmap();
        return Bitmap.createBitmap(original, 0, 0, original.getWidth(), original.getHeight(),
                mPhotoView.getImageMatrix(), true);

but the result is bad, because there are black areas, and I don't know why... I just want extract only the area with the picture and not all PhotoView.

enter image description here

How to extract without background unused?

Thank you very much guys!

anthony
  • 7,653
  • 8
  • 49
  • 101

1 Answers1

0

PhotoView extends ImageView so you can just call getDrawable() on the Photoview to get a Drawable.

Once you have the Drawable, if it is always a BitmapDrawable, you can just call getBitmap() on it and you have your bitmap. If you cannot guarantee that, you can start with reading through this question, and find the best way to convert.

This of course would ignore any zooming or transformation that is done to the view. If that is important to retain, then this answer is not relevant. Sorry.

Community
  • 1
  • 1
Stephen
  • 4,041
  • 22
  • 39
  • @anthony Are you trying to get the original image back out, or are you trying to get a new image with the transformation the user has set applied to it? – Stephen Apr 19 '17 at 16:28
  • @anthony I tried it out this way and it worked just fine. https://bitbucket.org/randomsnippets/http-stackoverflow.com-questions-43473786 I am still not sure if you are trying to capture the transformation applied to the view by the user, but if you are just trying to get the original image, this way should work. – Stephen Apr 19 '17 at 20:15
  • Stephen: I just want to extract visible part (=crop part actually) of original bitmap to another. – anthony Apr 20 '17 at 06:31