我是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()
修改
我最终在这里找到了答案:
http://pyglet.org/doc-current/programming_guide/image.html#simple-image-blitting
解决方案是:
imageWidth = 100
imageHeight = 100
imageName.width = imageWidth
imageName.height = imageHeight
这将调整为图像大小以显示为100x100
答案 0 :(得分:0)
遇到这个老人,所以对于任何孤独的游侠来说,就像我一样。更改.width
和.height
在很多情况下(或者在所有这些日子里都没有用)?
为了成功更改图像分辨率,您需要修改它的.scale
属性。
以下是我用来调整图片大小的代码片段:
from pyglet.gl import *
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
image = pyglet.image.load('test.png')
height, width = 800, 600 # Desired resolution
# the min() and max() mumbo jumbo is to honor the smallest requested resolution.
# this is because the smallest resolution given is the limit of say
# the window-size that the image will fit in, there for we can't honor
# the largest resolution or else the image will pop outside of the region.
image.scale = min(image.height, height)/max(image.height, height)), max(min(width, image.width)/max(width, image.width)
# Usually not needed, and should not be tampered with,
# but for a various bugs when using sprite-inheritance on a user-defined
# class, these values will need to be updated manually:
image.width = width
image.height = height
image.texture.width = width
image.texture.height = height