PIL在windwos系统下Image.show无法显示图片问题的解决方法

环境:1.win7 64位

   2.python 2.7.8

   3.PIL-1.1.7.win32-py2.7

在运行一下例子时候出现问题:

#-*-coding:utf-8-*-
__author__ = 'Hmily'
import Image
im=Image.open('pil.jpg')
print im.format,im.size,im.mode
im.show()

问题:图片无法显示

解决方法:

打开PIL安装目录:C:\Python27\Lib\site-packages\PIL

找到ImageShow.py文件,打开文件修改第99行代码

if sys.platform == "win32":

    class WindowsViewer(Viewer):
        format = "BMP"
        def get_command(self, file, **options):
            return "start /wait %s && del /f %s" % (file, file)
    register(WindowsViewer)

 将代码:

return "start /wait %s && del /f %s" % (file, file)

修改为:

return "start /wait %s && PING 127.0.0.1 -n 5 > NUL && del /f %s" % (file, file)

 重新运行代码:

  参考:http://www.thecodingforums.com/threads/python-pil-and-vista-windows-7-show-not-working.707158/    8楼

 

posted @ 2014-10-09 13:11  国产毛毛虫  阅读(632)  评论(0编辑  收藏  举报