Android: draw outside a closed path, not inside

I draw a filled polygon on canvas in android.

canvas.drawPath(path,myPaint); 

Now I want to do exactly the opposite: Fill the area outside the polygon.

how can i tell the paint to fill the outer area - the area that is not covered by the polygon?

+6
source share
2 answers

It can be complicated or very simple.

The hard way:

Create a path exactly like your polygon, except that do not close it. Continue on to the nearest wall. Draw around the walls. Close and fill. In code, this is not too much fun.

A simple way:

The color of the canvas. Draw a polygon.

Good luck.

+2
source

just use

 path.setFillType(FillType.INVERSE_EVEN_ODD); 
+7
source

Source: https://habr.com/ru/post/916871/


All Articles