2012-12-19 63 views
2

我想獲得窗口的照片(縮略圖),我已經有了它的處理(hwnd)在Windows操作系統中使用python。如何捕捉窗口照片(縮略圖)?

+0

你看過http://stackoverflow.com/a/2447245/530160? –

+0

嘗試搜索。你可以從這裏開始 - http://stackoverflow.com/questions/3260559/how-to-get-a-window-or-fullscreen-screenshot-in-python-3k-without-pil – Aesthete

+1

@NickODell - OP想用蟒蛇。 – Aesthete

回答

1

link i posted in your question comments,我能夠得到一個示例工作縮略圖我的python解釋器窗口。

from PIL import ImageGrab, Image 
import win32gui 

hwnd = 2622054 # My python intepreter window 
thumbnailsize = 128, 128 

# Set the current window to your window 
win32gui.SetForegroundWindow(hwnd) 
# Get the size of the window rect. 
bbox = win32gui.GetWindowRect(hwnd) 
# Grab the image using PIL and thumbnail. 
img = ImageGrab.grab(bbox) 
img.thumbnail(thumbnailsize, Image.ANTIALIAS) 
# Save. 
img.save('c:/test/test.png')