您的位置:首页 > 编程语言 > Python开发

解决im.show()不能显示图片问题

2016-03-27 19:09 615 查看
  在Python中有一个很有用的图像处理插件:PIL(Python Imageing Library),PIL目前版本为1.1.7,在PIL处理图像的时候,有时show()一下图片,发现如下:


图(1)无法显示图片

  出现该问题的原因如下:

  


  解决该问题的步骤如下:

  1.打开X:\Python27\Lib\site-packages\PIL\ImageShow.py文件,将第99行替换为如下语句:  

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


  如图(2)所示:


图(2)修改..Python27\Lib\site-packages\PIL\ImageShow.py里的第99行语句

  2.调用show()函数,代码如下:  

#-*- coding: UTF-8 -*-

import Image

str1 = 'C:/Users/Administrator/Desktop/2.png'

im = Image.open(str1)
#print im.format,im.size,im.mode

im.show()


  效果如下:


图(2) PIL里用show()显示图片的效果

参考地址:http://www.thecodingforums.com/threads/python-pil-and-vista-windows-7-show-not-working.707158/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息