开发者

(py)cairo - fill

开发者 https://www.devze.com 2023-01-25 13:02 出处:网络
is there a way to fill everyt开发者_运维问答hing outside of a closed path (polygon)? Background: I\'d like to render some maps with coastlines - so sometimes I need to fill the sea with blue color, s

is there a way to fill everyt开发者_运维问答hing outside of a closed path (polygon)?

Background: I'd like to render some maps with coastlines - so sometimes I need to fill the sea with blue color, so I thought it would be the easiest and in my situation the most efficient to fill everything outside of this coastline polygon with blue color.

Thanks in advance!


You can add a rectangle covering the whole drawing area to your coastline path and set the fill rule to cairo.FILL_RULE_EVEN_ODD. Calling fill() after this fills the area outside your original path. (If you choose the correct orientation for your rectangle you can skip setting the fill rule.)


Draw a big blue rectangle over the entire cairo surface and then draw your coastline on top of that?


While you could create a closed path the size of the surface and then fill it with a solidpattern (the fill rule won't matter for a simple rectangle), it would be easier to just use the context paint() method which will fill the current clip region (that is initially set to the entire surface). It's important to do this before drawing the map/coastline boundaries and filling them so they will be on top of the background.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号