(py)开罗 - 填充
有没有办法填充闭合路径(多边形)之外的所有内容?
背景:我想用海岸线渲染一些地图 - 所以有时我需要用蓝色填充海洋,所以我认为用蓝色填充海岸线多边形之外的所有内容是最简单的,在我的情况下也是最有效的颜色。
提前致谢!
is there a way to fill everything 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将覆盖整个绘图区域的矩形添加到海岸线路径中,并将填充规则设置为 cairo.FILL_RULE_EVEN_ODD 。之后调用
fill()
会填充原始路径之外的区域。 (如果您为矩形选择了正确的方向,则可以跳过设置填充规则。)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
. Callingfill()
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.