pyCairo堆栈图像 [英] pyCairo Stack images

查看:78
本文介绍了pyCairo堆栈图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用pycairo合成图像.

I'm using pycairo to compose images.

目前,我正在从基本图像创建ImageSurface,并从此Surface设置上下文.

Currently I am creating my ImageSurface from a base image and setting a Context from this Surface.

surface = cairo.ImageSurface.create_from_png("base.png")
ctx = cairo.Context (surface)

然后我可以在顶部添加文本:

Then I can for example add text on top:

# 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

除了文本,我还需要加载其他图像,然后将其放在特定位置的基础图像之上.

Apart from text, I also need to load other images and put then on top of my base image at specific locations.

我应该根据新图像创建另一个表面,然后堆叠这些表面,还是可以像处理文本一样将新图像直接加载到特定位置的上下文中?

Should I create another surface from a new image and then stack the surfaces, or can I directly load the new image into the context at an specific location as I do with text?

推荐答案

您不能直接将图像加载到上下文中.您需要更多的表面.

You cannot directly load images into a context. You need more surfaces.

这篇关于pyCairo堆栈图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆