Search code examples
androidandroid-canvasrect

Creating 'hole' in a RectF


I have a canvas-based drawing app that when zoomed in, I draw a miniature of the overall drawing in one corner as a scaled Bitmap. I also have a small RectF that I draw over top of the miniature, which shows you where you are in the drawing. See first attached image.

Miniature of larger drawing

What I would like to do is to draw the scaled bitmap, then draw a RectF of the same size over top of it, with an alpha value that allows you to see the miniature, and then finally, punch a hole in the RectF that shows you where you are and allows you a clearer view of the miniature. See second attached image.

RectF with 'hole'

I've considered using a bitmap for the RectF with the hole already 'built-in', but as the hole will both be moving depending on location, and will change in size depending on scale factor, I need to do it dynamically.

I've looked over the RectF docs but don't see anything that would allow me to clip the RectF with a smaller RectF that would make the 'hole'. Any ideas?


Solution

  • You could use a Path with filling option. moveTo 0,0 and frame the whole minipic, then moveTo the first corner inside and frame/create the hole. Not sure if it works but you can also add shapes to the path.