PIL Image module Show function does not display picture properly

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.