当我尝试以下操作时,我希望这两个图像是相同的,但它们不是!
我是这个开罗的新手,这让我发疯。
#!/usr/bin/env python
import cairo
WIDTH, HEIGHT = 256, 256
pat = cairo.LinearGradient (0.0, 0.0, 0.0, 1.0)
pat.add_color_stop_rgb (1, 1, 0, 0) # First stop
pat.add_color_stop_rgb (0.5, 0, 1, 0) # Mid stop
pat.add_color_stop_rgb (0, 0, 0, 1) # Last stop
# A surface
surface0 = cairo.ImageSurface (cairo.FORMAT_RGB24, WIDTH, HEIGHT)
ctx0 = cairo.Context (surface0)
ctx0.scale (WIDTH, HEIGHT)
ctx0.set_source(pat)
ctx0.paint()
# My second surface
surface1 = cairo.ImageSurface (cairo.FORMAT_RGB24, WIDTH, HEIGHT)
ctx1 = cairo.Context (surface1)
ctx1.scale (WIDTH, HEIGHT)
ctx1.set_source_surface(surface0, 0, 0)
ctx1.set_operator (cairo.OPERATOR_SOURCE)
ctx1.paint()
surface0.write_to_png("example0.png")
surface1.write_to_png("example1.png")