2

表面に移動要素を描画するために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
4

1 に答える 1