Loading an image in Python (Error) part_2
This code didn't show my picture. The picture really exists :) Does anybody know why this doesnt work? Thanks in advance!
from PIL import开发者_运维技巧 Image
im = Image.open("D:\\Python26\\PYTHON-PROGRAMME\\bild.jpg")
im.show()
You probably need to call the load() method to force the open() method to do its work. open is lazy.
Try:
from PIL import Image
im = Image.open("D:\\Python26\\PYTHON-PROGRAMME\\bild.jpg")
im.load()
im.show()
Idea #2: Patch PIL's file Image.py to have a potentially more robust approach to using the Windows shell to display your image. In the method _showxv, replace the following lines:
if os.name == "nt":
command = "start /wait %s && del /f %s" % (file, file)
with
if os.name == "nt":
command = "%s" % file
I suspect that the problem with the existing implementation is that the del command after the && is running immediately after the start command rather than after the result of the start command finishes. Thus, the file has already been deleted by the time that the image viewer is ready to load and display it.
Do back up your copy of the code before patching it.
精彩评论