mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 01:16:16 +03:00
Fully document PIL.ImageGrab
This commit is contained in:
parent
bc0f53aceb
commit
cf7b72f9b9
|
@ -17,33 +17,31 @@
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
##
|
|
||||||
# (New in 1.1.3) The <b>ImageGrab</b> module can be used to copy
|
|
||||||
# the contents of the screen to a PIL image memory.
|
|
||||||
# <p>
|
|
||||||
# The current version works on Windows only.</p>
|
|
||||||
#
|
|
||||||
# @since 1.1.3
|
|
||||||
##
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# built-in driver (1.1.3 and later)
|
# built-in driver (1.1.3 and later)
|
||||||
grabber = Image.core.grabscreen
|
grabber = Image.core.grabscreen
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
try:
|
||||||
# stand-alone driver (pil plus)
|
# stand-alone driver (pil plus)
|
||||||
import _grabscreen
|
import _grabscreen
|
||||||
grabber = _grabscreen.grab
|
grabber = _grabscreen.grab
|
||||||
|
except ImportError:
|
||||||
|
# allow the module to be imported by autodoc
|
||||||
|
grabber = None
|
||||||
|
|
||||||
##
|
|
||||||
# (New in 1.1.3) Take a snapshot of the screen. The pixels inside the
|
|
||||||
# bounding box are returned as an "RGB" image. If the bounding box is
|
|
||||||
# omitted, the entire screen is copied.
|
|
||||||
#
|
|
||||||
# @param bbox What region to copy. Default is the entire screen.
|
|
||||||
# @return An image
|
|
||||||
# @since 1.1.3
|
|
||||||
|
|
||||||
def grab(bbox=None):
|
def grab(bbox=None):
|
||||||
|
"""
|
||||||
|
Take a snapshot of the screen. The pixels inside the bounding box are
|
||||||
|
returned as an "RGB" image. If the bounding box is omitted, the entire
|
||||||
|
screen is copied.
|
||||||
|
|
||||||
|
.. versionadded:: 1.1.3
|
||||||
|
|
||||||
|
:param bbox: What region to copy. Default is the entire screen.
|
||||||
|
:return: An image
|
||||||
|
"""
|
||||||
size, data = grabber()
|
size, data = grabber()
|
||||||
im = Image.frombytes(
|
im = Image.frombytes(
|
||||||
"RGB", size, data,
|
"RGB", size, data,
|
||||||
|
@ -55,14 +53,17 @@ def grab(bbox=None):
|
||||||
return im
|
return im
|
||||||
|
|
||||||
##
|
##
|
||||||
# (New in 1.1.4) Take a snapshot of the clipboard image, if any.
|
|
||||||
#
|
|
||||||
# @return An image, a list of filenames, or None if the clipboard does
|
|
||||||
# not contain image data or filenames. Note that if a list is
|
|
||||||
# returned, the filenames may not represent image files.
|
|
||||||
# @since 1.1.4
|
|
||||||
|
|
||||||
def grabclipboard():
|
def grabclipboard():
|
||||||
|
"""
|
||||||
|
Take a snapshot of the clipboard image, if any.
|
||||||
|
|
||||||
|
.. versionadded:: 1.1.4
|
||||||
|
|
||||||
|
:return: An image, a list of filenames, or None if the clipboard does
|
||||||
|
not contain image data or filenames. Note that if a list is
|
||||||
|
returned, the filenames may not represent image files.
|
||||||
|
"""
|
||||||
debug = 0 # temporary interface
|
debug = 0 # temporary interface
|
||||||
data = Image.core.grabclipboard(debug)
|
data = Image.core.grabclipboard(debug)
|
||||||
if isinstance(data, bytes):
|
if isinstance(data, bytes):
|
||||||
|
|
15
docs/reference/ImageGrab.rst
Normal file
15
docs/reference/ImageGrab.rst
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
.. py:module:: PIL.ImageGrab
|
||||||
|
.. py:currentmodule:: PIL.ImageGrab
|
||||||
|
|
||||||
|
:mod:`ImageGrab` Module (Windows-only)
|
||||||
|
======================================
|
||||||
|
|
||||||
|
The :py:mod:`ImageGrab` module can be used to copy the contents of the screen
|
||||||
|
or the clipboard to a PIL image memory.
|
||||||
|
|
||||||
|
.. note:: The current version works on Windows only.
|
||||||
|
|
||||||
|
.. versionadded:: 1.1.3
|
||||||
|
|
||||||
|
.. autofunction:: PIL.ImageGrab.grab
|
||||||
|
.. autofunction:: PIL.ImageGrab.grabclipboard
|
|
@ -12,4 +12,5 @@ Reference
|
||||||
ImageFile
|
ImageFile
|
||||||
ImageFilter
|
ImageFilter
|
||||||
ImageFont
|
ImageFont
|
||||||
|
ImageGrab
|
||||||
../PIL
|
../PIL
|
||||||
|
|
Loading…
Reference in New Issue
Block a user