首页 > 解决方案 > 如何将路径与pycairo合并?

问题描述

我正在使用curve_to用 pycairo 绘图,这是代码:

ctx.move_to(0.4,0.8)
ctx.curve_to(0.3,0.4 ,0.4,0.4 ,0.4,0.4)
ctx.set_source_rgb(0,0,0)
ctx.set_line_width(0.001)
ctx.fill()

ctx.move_to(0.4,0.8)
ctx.line_to(0.5,0.8)
ctx.set_source_rgb(0,0,0)
ctx.set_line_width(0.001)
ctx.stroke()


ctx.move_to(0.5,0.8)
ctx.curve_to(0.6,0.4 ,0.5,0.4 ,0.5,0.4)
ctx.set_source_rgb(0,0,0)
ctx.set_line_width(0.001)
ctx.fill()

ctx.move_to(0.4,0.4)
ctx.line_to(0.5,0.4)
ctx.set_source_rgb(0,0,0)
ctx.set_line_width(0.001)
ctx.stroke()

在此处输入图像描述

我想填充对象,但如您所见,我无法全部填充,因为它们是分开的,尚未合并。所以我认为这里最接近的方法是合并它们。

标签: pythoncairopycairo

解决方案


关于什么:

    ctx.set_source_rgb(0,0,0)
    ctx.set_line_width(0.001)

    ctx.move_to(0.5,0.8)
    ctx.line_to(0.4,0.8)
    ctx.curve_to(0.3,0.4 ,0.4,0.4 ,0.4,0.4)

    ctx.move_to(0.4,0.4)
    ctx.line_to(0.5,0.8)
    ctx.curve_to(0.6,0.4 ,0.5,0.4 ,0.5,0.4)

    ctx.fill()

我对此进行了测试,它形成了一个填充区域。我不确定它是否正确。


推荐阅读