Python windows 7 screenshot without PIL Python windows 7 screenshot without PIL python python

Python windows 7 screenshot without PIL


Get PIL for win-amd64-py2.7 at http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil.

from PIL import ImageGrabim = ImageGrab.grab()im.save('screenshot.png')

Update: use pywin32 (http://sourceforge.net/projects/pywin32/) instead of PIL to take screenshots of multiple virtual screens:

import win32gui, win32ui, win32con, win32apihwin = win32gui.GetDesktopWindow()width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)hwindc = win32gui.GetWindowDC(hwin)srcdc = win32ui.CreateDCFromHandle(hwindc)memdc = srcdc.CreateCompatibleDC()bmp = win32ui.CreateBitmap()bmp.CreateCompatibleBitmap(srcdc, width, height)memdc.SelectObject(bmp)memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), win32con.SRCCOPY)bmp.SaveBitmapFile(memdc, 'screenshot.bmp')


32- or 64-bit Windows is irrelevant here; it is the 'bit-ness' of Python and its modules that matter. If you are running 32-bit-compiled Python, 32-bit-compiled PIL will work just fine on 64-bit Windows.

On the other hand, if you are running 64-bit-compiled Python, you need to find or custom-compile a 64-bit-compiled version of PIL to match.

Edit:

You can download a 64-bit-compiled version of PIL from http://www.lfd.uci.edu/~gohlke/pythonlibs/ - specifically, you want PIL-1.1.7.win-amd64-py2.7.‌exe


I got the same problem on PIL or pyscreenshot, here's how I solved it.

Right-click on python.exe, Properties, Compatibility tab, check 'Disable display scaling on high DPI settings'. Repeat for pythonw.exe.