【发布时间】:2017-11-07 14:40:02
【问题描述】:
我正在使用 pycairo 来构图。
目前我正在从基础图像创建 ImageSurface 并从此 Surface 设置上下文。
surface = cairo.ImageSurface.create_from_png("base.png")
ctx = cairo.Context (surface)
然后我可以例如在顶部添加文本:
# draw text
ctx.select_font_face('Sans')
ctx.set_font_size(20)
ctx.move_to(10, 90)
ctx.set_source_rgb(1.00, 0.83, 0.00) # yellow
ctx.show_text('Hello World')
最后是抚摸和保存
ctx.stroke()
surface.write_to_png('hello_world.png') # write to file
除了文本之外,我还需要加载其他图像,然后将其放在我的基础图像之上的特定位置。
我应该从新图像创建另一个表面然后堆叠表面,还是可以像处理文本一样直接将新图像加载到特定位置的上下文中?
【问题讨论】: