so I'm trying to find the region of the current image in the ImageView and fill that region with a different image. Here is the original image Empty Circle inside an imageView. The imageView has a drawable of a circle inside. Then I'm trying to make it into something like this Circle filled with image inside an ImageView when a user chooses an image. I don't want to manually Photoshop a circle image. I am just hoping to fill the region with another image. I have tried SRC_IN
method from AlphaComposite
, but for android, I can't convert from BitMap
to graphics2D
. If anyone knows how to solve this using the BitmapFactory
in android, I would really appreciate your help. Thank you.
Asked
Active
Viewed 906 times
2

Alan_Xu
- 23
- 4
-
See this http://stackoverflow.com/q/16208365/2556111 – ramaral Nov 29 '13 at 17:55
-
Hi ramaral, thanks for the link, but in the link, it uses the `Canvas` to draw a circle region then uses `canvas.drawBitmap(sbmp, rect, rect, paint);` to draw the `ImageView` with a bitmap inside. While this method would work for a easily defined shape. What I am looking for will be flexible to different shapes (not exactly easy to draw). The circle image I have above is simpliy an example. I am looking for the method of "filling existing drawable image with new drawable image" instead. And not reshaping `ImageView'. I appreciate your help though. Thanks. – Alan_Xu Nov 29 '13 at 18:30
1 Answers
0
The other solution besides Bitmaps, may be too simple for whatever you are trying to achieve otherwise I think it would have occurred to you. I'm just pointing it out in case you have "code blindness" and are trying to over-engineer the solution because you've worked on it for too long (we've all done it)
It is to have that circle/shape image saved as a png with the area you want filled being transparent then set it as the drawable for an ImageView (etc.) then in a RelativeLayout lay this view over the image you want to fill the area and apply a transparent background to the shape view OR simply set the fill image as the background for the shape view.

Nick Cardoso
- 20,807
- 14
- 73
- 124
-
Yes, but if I make the shape transparent, I would need the `getTransparentRegion()`. According to the documents, this method call was added since API 1. It is defaulted to return null. If ever I would want to use this method for the `Drawable` class, I would need to override it and provide a method myself to return the bitmap region which is transparent. I have gone over some of the similar problems but would not find something that can perform this operation well (others' method may only discover a portion of the transparent region). Thanks. – Alan_Xu Dec 02 '13 at 01:43