问题描述
我想使用python截取屏幕截图。
I want to take a screenshot using python.
我尝试过使用PIL,但是因为我使用的是64位Windows而且python PIL不起作用(我只能这样做)找到32位PIL版本)。顺便说一句,我使用的是python 2.7.1。
I have tried using PIL, but since I am using 64bit windows and python PIL does not work (I could only find 32bit PIL versions). I am using python 2.7.1 by the way.
我想截取屏幕截图,这并不重要,只要它可以占用1个以上每秒的速度。最好它也应该能够裁剪它所截取的区域,但这并不是最重要的。
I want to take a screenshot, it doesn't really matter how, as long as it can take more than 1 per second in speed. Preferably it should also be able to crop the area it takes a screenshot of, but that's not of the utmost importance.
主要问题似乎是我正在运行64位和许多东西似乎与此不相容。如果可能的话,我真的不想回到32位。
是否有任何程序或模块可以执行此操作?
The main problem seems to be I'm running on 64bit and a lot of things seem incompatible with that. I don't really want to move back to 32bit though if at all possible.Are there any programs or modules that can do this?
推荐答案
获取PIL for win-amd64-py2.7在)而不是PIL来截取多个虚拟屏幕的截图:
Update: use pywin32 (http://sourceforge.net/projects/pywin32/) instead of PIL to take screenshots of multiple virtual screens:
import win32gui, win32ui, win32con, win32api
hwin = 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')
这篇关于没有PIL的Python windows 7截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!