我尝试在Python语言中调整图像的大小,然后用调整后的图像加载一个cocos2d精灵。但是,尝试初始化cocos2d精灵会导致找不到资源的错误。重现问题的示例代码:
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()并没有解决问题。
操作系统是装有Python版本3.6.4的Windows 10。
发布于 2018-06-28 23:11:14
它原来是pyglet中用来加载资源的方法。我不得不对图像重新编制索引。图像目录中的文件,其中动态添加和pyglet创建现有图像的索引。有关答案,请参阅https://stackoverflow.com/a/16438410/6350693。
https://stackoverflow.com/questions/50928663
复制相似问题