Environment: Win7+python 2.7.6
import Imageim=Image.open(‘3.png‘)im.show()
Show Results:
Always show loading, cannot open, or display content does not exist etc.
Directly double-click the picture to display it normally
Workaround: (X: Installation path for Python, default C-drive)
x:/python26/lib/site-packages/pil/imageshow.py, the 99th Line (near) is replaced by:
Return "start/wait%s && PING 127.0.0.1-n 5 > NUL && del/f%s"% (file, file)
PING 127.0.0.1-n 5 > NUL
The meaning is:
Ping 127.0.0.1 is your own host
-N 5 ping5 Times, takes about 4 seconds
NUL does not display the ping results on the screen
Specific reasons: (personal to the reference translation results, for reference only, poor English level, may be more wrong, English version of the following reference link)
The default image viewer on Windows XP is able to block working mode-this means that the command will wait until the image window is closed for execution.
Because of this behavior, they (Python) create a command line to delete the temporary file after the image is displayed. (see imageshow.py, near line 99)
Windows Vista is not the same, and once the command is executed it returns immediately.
As a result, the temporary file is immediately deleted and the picture viewer cannot have enough time to load the deleted image.
Then, add a useless command to the original command (PING 127.0.0.1-n 5 > NUL) to buy time for the image loading, solve the problem.
PIL Image module Show function does not display picture properly