Reputation: 376
I want to get the photo(thumbnail) of a window which I already have it's handle (hwnd) using python in windows os.
Upvotes: 2
Views: 1226
Reputation: 18858
From the link i posted in your question comments, I was able to get a sample working that thumbnails my python interpreter window.
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')
Upvotes: 2