【发布时间】:2018-11-28 10:23:09
【问题描述】:
我正在尝试在 Python 中调整图像的大小,然后使用调整后的图像加载 cocos2d 精灵。但是,尝试初始化 cocos2d sprite 会导致找不到资源的错误。重现问题的示例代码:
from pathlib import Path
import cocos
from PIL import Image
im = Image.open("in.jpg")
im.thumbnail((600, 900))
im.save("out.jpg", "JPEG")
im.close()
file = Path("out.jpg")
if file.is_file():
print("File exists")
sprite = cocos.sprite.Sprite("out.jpg")
这会导致错误
pyglet.resource.ResourceNotFoundException: Resource "out.jpg" was not found on the path. Ensure that the filename has the correct captialisation.
但是,输出是:
File exists
第二次运行它不会出错,因为out.jpg 已在上一次运行中创建。删除out.jpg 并再次运行它会产生错误。
添加im.close() 并没有解决问题。
操作系统为 Windows 10,Python 版本为 3.6.4。
【问题讨论】:
-
看来问题出在
pyglet.resource.image(image),它在Cocos框架中加载了图片
标签: python python-3.x cocos2d-python