Windows上的Python映像库show() [英] Python imaging library show() on Windows

查看:100
本文介绍了Windows上的Python映像库show()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个脚本,该脚本可以从Web下载各种图像文件,然后使用PIL对它们进行一些处理.该脚本使用urlretreive将图像转储到临时文件中,现在我只是尝试使用PIL image.show()方法在查看器中打开它们.这是代码的相关部分:

I am working on a script that downloads various image files from the web and then does some processing on them using the PIL. The script uses urlretreive to dump the images to temporary files, and right now I'm just trying to open them in a viewer using the PIL image.show() method. Here is the relevant portion of the code:

def main():

link_queue = Queue.Queue()
image_queue = Queue.Queue()

links = get_image_links('test_search')

for link in links:
    link_queue.put(link)

for image in xrange(len(links)):
    #create image downloading threads
    t = ImageDownloadingThread(link_queue, image_queue)
    t.setDaemon(True)
    t.start()

link_queue.join()

image_data = image_queue.get()
image_file, image_url = image_data[0][0], image_data[1][0] 
#get the first image downloaded and take a look
image = Image.open(image_file)
image.show()

不幸的是,虽然临时文件似乎可以正常加载(Image.open不会返回任何错误),但是当调用image.show()时,查看器中什么也没得到:

Unfortunately, while the temporary file seems to load OK (Image.open doesn't return any errors) I get nothing in the viewer when image.show() is called:

我还尝试打开本地非临时文件,以防出现问题并得到相同的结果.操作系统为Windows Vista 32位SP2.对可能出什么问题有任何想法吗?

I have also tried opening local, non-temporary files, in case that was part of the problem and get the same result. The OS is Windows Vista 32 bit SP2. Any ideas on what might be going wrong?

推荐答案

show()尝试使用start /wait命令在临时图像文件上执行默认图像查看器. /wait参数应该等待,直到查看器退出,以便可以删除文件.不幸的是,Vista和Windows 7下的默认查看器无法正确响应/wait甚至在打开文件之前返回.该文件将被删除,然后才能显示.

show() tries to execute the default image viewer with a start /wait command on a temporary image file. The /wait parameter is supposed to wait until the viewer exits, so that the file can be deleted. Unfortunately the default viewer under Vista and Windows 7 does not respond properly to /wait and return even before they've opened the file; the file gets deleted before it can be displayed.

通常的解决方法是在PIL包中编辑ImageShow.py并添加一个额外的命令,以等待几秒钟,然后再删除该文件.这很麻烦,但是大多数时候都有效.有关详细信息,请参见 velocityreviews. com 此处位于StackOverflow .

The usual fix is to edit ImageShow.py in the PIL package and add an extra command to wait a few seconds before deleting the file. This is a kludge, but it works most of the time. Details at velocityreviews.com and here at StackOverflow.

解决此问题的另一种方法是将.bmp文件格式与在返回之前正确等待的程序相关联,例如mspaint.exe.

The other way to fix it is to associate the .bmp file format with a program that waits properly before returning, for example mspaint.exe.

这篇关于Windows上的Python映像库show()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆