【发布时间】:2015-09-28 10:48:32
【问题描述】:
我不想用pyCairo 填充多边形,但我希望某些区域不填充。例如,我想制作这样的东西:
灰色背景是 SVG 查看器的背景,因此代表图像的透明部分。
我尝试使用此代码:
import cairo
cairo.FILL_RULE_EVEN_ODD
svg_file_pointer = open('CairoPoly.svg', 'wb')
shape_container = cairo.SVGSurface(svg_file_pointer, 500, 500)
shape_description = cairo.Context(shape_container)
shape_description.rectangle(0, 0, 500, 500)
shape_description.clip_preserve()
shape_description.stroke()
shape_description.set_line_width(1)
shape_description.set_source_rgb(20/51, 0, 0)
for r in ((100, 100, 400, 400), (200, 200, 350, 300), (150, 110, 190, 390)):
shape_description.move_to(r[0], r[1])
shape_description.line_to(r[0], r[3])
shape_description.line_to(r[2], r[3])
shape_description.line_to(r[2], r[1])
shape_description.line_to(r[0], r[1])
shape_description.close_path()
shape_description.fill()
shape_container.finish()
svg_file_pointer.close()
del shape_container
但它不起作用。这可以用 pyCairo 完成吗?如果可以,怎么做?
【问题讨论】:
标签: python python-3.x svg polygons pycairo