问题描述
我正在使用Python Imaging Library,但无法在Windows Live Photo Gallery中成功打开图像.出现一条消息,提示没有选择照片或视频",而不是图像.
I'm using the Python Imaging Library and I am unable to open an image successfully in Windows Live Photo Gallery. There is a message that shows up saying "There are no photos or videos selected" instead of the image.
这是我尝试过的:
import Image
img = Image.open(r"C:\Users\User\Pictures\image.jpg")
img.show()
这与PIL手册教程中的内容几乎相同,所以我不确定哪里出了问题.
This is pretty much the same as in the PIL handbook tutorial, so I'm not sure where I'm going wrong.
推荐答案
文档说:
问题是您的程序以某种方式立即退出,该临时文件在退出时被删除,Windows等找不到该文件.作为临时解决方案,请尝试添加:
Problem is that your program exits immediately somehow, the temporary file is deleted upon exit and Windows etc. cannot find it. As a temporary solution, try adding:
import time
# Your code as above
time.sleep(30)
这将使程序在退出之前等待30秒.如果愿意,可以让它等待用户按下键.
This will make the program wait 30 seconds before exiting. If you prefer, you could make it wait the user to press a key.
看来您遇到临时文件问题.解决方法是,使用img.save("C:\Users\User\Pictures\test.jpg")
将图像保存在磁盘上的某个位置,然后使用您喜欢的图像查看器将其打开.每当您要显示经过处理的图像时,请再次调用save
,然后将图像重新加载到图像查看器中.
it seems like you are experiencing problems with temporary files. As a workaround, save the image somewhere on the disk using, say, img.save("C:\Users\User\Pictures\test.jpg")
and open it with your favorite image viewer. Whenever you want to show the processed image, call save
again and reload the picture in the image viewer.
这篇关于无法使用python PIL Image.show显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!