Pergunta

import cairo
import math

w = 2000
h = 2000

surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
ctx = cairo.Context(surface)
ctx.scale(w, h)

surface_path = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
ctx_path = cairo.Context(surface_path)
ctx_path.scale(w, h)

surface_circle = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
ctx_circle = cairo.Context(surface_circle)
ctx_circle.scale(w, h)

""" Lots of function calls that draw paths to surface_path and circles to surface_circle """

ctx.set_source_surface(surface_path, 0, 0)
ctx.paint()
ctx.set_source_surface(surface_circle, 0, 0)
ctx.paint()

surface_path.write_to_png("example.png")
surface_circle.write_to_png("example2.png")
surface.write_to_png("result.png")

Imgur link to saved images

I am attempting to compile two surfaces (one with lines, one with circles) onto one separate surface, then save that to a file.

Despite following what the documentation suggests should work, the final image ends up blank. I also tried calling flush() on surface_path and surface_circle, but that seemed to do nothing.

How could I combine the image info in surface_circle (example2.png) on top of surface_path (example.png), then output it to a file?

Foi útil?

Solução

Try calling ctx.identity_matrix() before your last few paint() calls.

As is right-now, thanks to your call to ctx.scale(w, h), you only get the top-left pixels of those other surfaces scaled up to fill all of the target surface.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top