如何捕捉窗口照片(缩略图)?

时间:2012-12-19 02:11:29

标签: python windows

我想在Windows操作系统中使用python获取一个窗口的照片(缩略图),我已经拥有它的句柄(hwnd)。

1 个答案:

答案 0 :(得分: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')