【发布时间】:2014-07-08 13:57:16
【问题描述】:
我正在使用 pyCairo 在表面上绘制移动元素。 为了获得更好的性能,我尝试使用“剪辑”功能仅重绘更大图像的更改部分。不幸的是,它会在图像上创建不需要的边缘。可以看到剪辑的边缘。有没有可能避免这种行为?
import math
import cairo
def draw_stuff(ctx):
""" clears background with solid black and then draws a circle"""
ctx.set_source_rgb (0, 0, 0) # Solid color
ctx.paint()
ctx.arc (0.5, 0.5, 0.5, 0, 2*math.pi)
ctx.set_source_rgb (0, 123, 0)
ctx.fill()
WIDTH, HEIGHT = 256, 256
surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context (surface)
ctx.scale (WIDTH, HEIGHT) # Normalizing the canvas
draw_stuff(ctx)
#Let's draw stuff again, this time only redrawing a small part of the image
ctx.save()
ctx.rectangle(0.2,0.2,0.2,0.2)
ctx.clip()
draw_stuff(ctx)
ctx.restore()
surface.write_to_png ("example.png") # Output to PNG
【问题讨论】:
-
你能提供一张不需要的边缘的屏幕截图吗?
-
StackOverflow 要求我有 10 名声望才能发布图片。上面的代码在黑色背景上输出一个大绿色圆圈。还有一个不需要的矩形,在“剪辑”之后的绘图发生的地方有一个狭窄的黑色边缘。