Created
June 18, 2012 10:28
-
-
Save romichi/2947785 to your computer and use it in GitHub Desktop.
指定のウィンドウのスクリーンショットをとる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding:utf-8 -*- | |
| import time | |
| import gtk | |
| import win32gui, win32com.client | |
| shell = win32com.client.Dispatch('WScript.Shell') | |
| shell.Run('Notepad') #メモ帳の起動 | |
| time.sleep(1) | |
| windowHandle = win32gui.FindWindow('notePad', None) #ハンドラの取得 | |
| w0, h0, w1, h1 = win32gui.GetWindowRect(windowHandle) #座標の取得 | |
| width, height = w1 - w0, h1 - h0 #幅と高さ | |
| root_window = gtk.gdk.get_default_root_window() | |
| pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height) #描写領域の確保 | |
| pixbuf.get_from_drawable(root_window, gtk.gdk.colormap_get_system(), w0, h0, 0, 0, width, height) #スクリーンキャプチャ | |
| pixbuf.save("notePad.png", "png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment