PIL图像show()在Windows 7上不起作用

cyb*_*org 14 python show windows-7 python-imaging-library

我想在Windows和其他平台上使用python显示图像.当我做:

from PIL import Image
im = Image.open('image.png')
im.show()
Run Code Online (Sandbox Code Playgroud)

我的默认查看器打开并告诉我Windows Photo Viewer can't open this picture because either this file was deleted,等等

该文件可能已被删除,因为PIL使用以下命令调用os: "start /wait %s && del /f %s" % (file, file)

我在这里找到了解决方法.他们建议将PIL的代码更改为"start /wait %s && PING 127.0.0.1 -n 5 > NUL && del /f %s" % (file, file).但是,我希望其他人能够使用我的代码.

有简单的解决方案吗?我应该寻找可以在跨平台上工作的PIL的替代方案吗?

cyb*_*org 12

好的,在这里找到了解决方案:

import webbrowser
webbrowser.open('image.png')
Run Code Online (Sandbox Code Playgroud)

它在我的机器上打开默认查看器,而不是浏览器.

还有os.startfile.

  • 这有助于显示(可能修改的)`im`对象/图像,就像之前使用`im.show()`一样?如果我想显示`im`怎么办?我想你可以将它保存到一些临时文件名然后使用它.. (2认同)