Python Imaging Library: ImageGrab Module(图像采集模块)
ImageGrab可以用来将屏幕或剪贴板的内容复制到一个图像内存中。目前的版本只在Windows上运行。
函数
grab
ImageGrab.grab() ⇒ image
ImageGrab.grab(bbox) ⇒ image
(版本1.1.3)获取屏幕快照,并返回一个“RGB”图像。边界框参数可用于仅复制屏幕的一部分。
grabclipboard
ImageGrab.grabclipboard() ⇒ image or list of strings or None
(版本1.1.3)获取剪贴板内容的快照,并返回一个图像对象或一个文件名列表。如果剪贴板不包含图像数据,那么这个函数将返回None。
您可以使用isinstance来检查函数是否返回了一个有效的图像对象,或者其他什么:
if isinstance(im, Image.Image):
... got an image ...
elif im:
for filename in im:
try:
im = Image.open(filename)
except IOError:
pass # ignore this file
else:
... got an image ...
else:
... clipboard empty ...