【问题标题】:How can capture a window photo (thumbnail)?如何捕捉窗口照片(缩略图)?
【发布时间】:2012-12-19 02:11:28
【问题描述】:

我想在 windows os 中使用 python 获取我已经拥有它的句柄 (hwnd) 的窗口的照片(缩略图)。

【问题讨论】:

标签: python windows


【解决方案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')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多