Android canvas - Draw a transparent hole over a rectangle

Viewed 1692

I've seen multiple posts about drawing a hole over a bitmap, however that doesn't seem to work when trying to draw over a filled area, such as a rectangle.

For example:

  1. I'm drawing a background with canvas.drawRect() and canvas.drawText()

enter image description here

  1. I'm drawing a red rectangle over the background with canvas.drawPaint() or canvas.drawRect()

enter image description here

  1. What I'm trying to achieve: Draw a circle that will reveal the background (hole)

enter image description here

Any suggestions? Thanks in advance!

Similar questions: Android canvas - Draw a hole & Erase bitmap parts using PorterDuff mode however the proposed solutions do not work when trying to draw over a rectangle instead of a bitmap. (i.e. I create the background dynamically using canvas.drawRect(), canvas.drawLines(), etc., I do not have a static bitmap).

0 Answers
Related