(py) cairo - fill in

Is there a way to fill everything outside the closed path (polygon)?

Prerequisites: I would like to display some maps with coastlines - so sometimes I need to fill the sea with blue, so I thought that it would be the easiest and in my situation the most effective for filling everything that is outside this coastline is a polygon with blue color.

Thanks in advance!

+3
source share
3 answers

You can add a rectangle covering the entire drawing area to your path to the shoreline and set the fill rule to cairo.FILL_RULE_EVEN_ODD. The call fill()then fills the area outside the source path. (If you choose the correct orientation for your rectangle, you can skip the fill rule setting.)

+2
source

Draw a large blue rectangle over the entire surface of Cairo, and then draw your coastline on top of it?

0
source

While you can create a closed path to fit the surface and then fill it with a solid pattern (the filling rule does not matter for a simple rectangle), it would be easier to just use the context paint () method, which will fill the current area of ​​the clip (initially set to the entire surface) . It is important to do this before drawing the borders of the map / coast and filling them so that they are on top of the background.

0
source

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


All Articles