[英]Python imaging library show() on Windows
我正在編寫一個腳本,從Web下載各種圖像文件,然后使用PIL對它們進行一些處理。 該腳本使用urlretreive將圖像轉儲到臨時文件,現在我只是嘗試使用PIL image.show()方法在查看器中打開它們。 以下是代碼的相關部分:
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()時,我在查看器中什么也得不到:
我也嘗試打開本地非臨時文件,以防出現問題,並獲得相同的結果。 操作系統是Windows Vista 32位SP2。 關於可能出錯的任何想法?
show()
嘗試在臨時圖像文件上使用start /wait
命令執行默認圖像查看器。 /wait
參數應該等到查看器退出,以便可以刪除該文件。 不幸的是,Vista和Windows 7下的默認查看器甚至在打開文件之前就沒有正確響應/wait
和返回; 文件在顯示之前被刪除。
通常的解決方法是在PIL包中編輯ImageShow.py並添加一個額外的命令,等待幾秒鍾才能刪除文件。 這是一個kludge,但它大部分時間都有效。 詳情請查看velocityreviews.com和StackOverflow 。
另一種解決方法是將.bmp
文件格式與在返回之前正確等待的程序相關聯,例如mspaint.exe。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.