我正在尝试在黑色背景上显示具有透明度的 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 表面上不再平滑移动