Unable to show an image using python PIL Image.show

蹲街弑〆低调 提交于 2019-12-14 02:08:01

问题


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.

This is what I've tried:

import Image

img = Image.open(r"C:\Users\User\Pictures\image.jpg")
img.show()

This is pretty much the same as in the PIL handbook tutorial, so I'm not sure where I'm going wrong.


回答1:


The documentation says:

On Windows, it [show()] saves the image to a temporary BMP file, and uses the standard BMP display utility to show it.

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)

This will make the program wait 30 seconds before exiting. If you prefer, you could make it wait the user to press a key.

EDIT: 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.



来源:https://stackoverflow.com/questions/16428082/unable-to-show-an-image-using-python-pil-image-show

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!