我是 Pyglet (和 stackoverflow)的新手,似乎无法找到如何调整图像大小。
'pipe.png' 是我正在尝试调整大小的图像。
使用这段代码,由于窗口尺寸太小,图像没有完全显示。
我想调整图像的大小,使其适合窗口内部。
“pipe.png”的当前大小为 100x576。
import pyglet
window = pyglet.window.Window()
pyglet.resource.path = ["C:\\"]
pipe = pyglet.resource.image('pipe.png')
pyglet.resource.reindex()
@window.event
def on_draw():
window.clear()
pipe.blit(0, 0)
pyglet.app.run()
Run Code Online (Sandbox Code Playgroud)
编辑:
我最终在这里找到了答案:
http://pyglet.org/doc-current/programming_guide/image.html#simple-image-blitting
解决办法是:
imageWidth = 100
imageHeight = 100
imageName.width = imageWidth
imageName.height = imageHeight
Run Code Online (Sandbox Code Playgroud)
这将调整图像大小以显示为 100x100