0

我正在尝试在黑色背景上显示具有透明度的 png 图像,在表面上缓慢移动它,但是很多帧都包含白色像素。(根本不应该存在)

维基媒体标志上的白色像素

徽标表面是这样创建的:

self.logo_surface = cairo.ImageSurface.create_from_png(image)

每一帧都是这样绘制的:我将它移动到一个新位置,然后将图像缩小到 15x15px

def draw(self, ctx):
    # scale image and move it to a right place
    ctx.save()
    ctx.translate(self.left, self.top)
    ctx.scale(self.scale_xy, self.scale_xy)
    ctx.set_source_surface(self.logo_surface)

    #Here i tried different filters but without improvement in reducing white flashes
    ctx.get_source().set_filter(cairo.FILTER_FAST)

    ctx.paint()
    ctx.restore()

left, top, scale_xy 是浮动的。Left 和 top 每帧都有一点变化。

我怎样才能防止这些闪光?

编辑:

1) 使用 get_data 提取来自最终表面的数据。

buf = self.surface.get_data()
a = numpy.frombuffer(buf, numpy.uint8)

2)当 translate 被赋予整数值时,不会发生这种效果:

ctx.translate(int(self.left), int(self.top))

但随后图像在 100x100px 表面上不再平滑移动

4

1 回答 1

0

维基媒体标志在透明和彩色部分之间包含一些白色像素。因为它是一张大图,除非放大得很近,否则无法看到。如果使用 cairo 缩小比例,有时会碰巧使用那些“白色”像素值 - 因此图像上会闪烁白色像素。

于 2014-08-07T17:04:21.330 回答