[英]Using Pyglet to scale gif to screen
任何人都可以讓我的代碼更加清晰,為什么當我嘗試將我的 gif 縮放到全屏時,一半屏幕是白色的,而另一個是 gif(動畫)? 這是使用 Pyglet python 模塊。
這是我的代碼以及問題的圖像:
'Load animation'
animation = pyglet.image.load_animation('Goober#13427G.gif')
animSprite = pyglet.sprite.Sprite(animation)
# 'Scale image to screen *harcoded*'
# animSprite.scale_x = 3.2
# animSprite.scale_y = 1.71
' Get display and create a fullscreen window while scaling gif to screen'
display = pyglet.canvas.Display()
screen = display.get_screens()
H_ratio = max(animSprite.height, screen[1].height) / min(animSprite.height, screen[1].height)
W_ratio = max(animSprite.width, screen[1].width) / min(animSprite.width, screen[1].width)
animSprite.scale = min(H_ratio, W_ratio)
window = pyglet.window.Window(width=screen[1].width, height=screen[1].height, fullscreen=True, screen=screen[1])
r, g, b, alpha = 1, 1, 1, .5
pyglet.gl.glClearColor(r, g, b, alpha)
@window.event
def on_draw():
window.clear()
animSprite.draw()
pyglet.app.run()
```[Gif with second half of screen to the right is white][1]
[1]: https://i.stack.imgur.com/JsbJy.jpg
嘗試縮放每個軸。
animSprite.scale_x = W_ratio
animSprite.scale_y = H_ratio
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.