What imaging modules for python will allow you to take a specific size screenshot (not whole screen)? I have tried PIL, but can't seem to make ImageGrab.grab() select a small rectangle and i have tried PyGame but i can't make it take a screen shot outside of it's main display panel
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
You can use pyscreenshot module.
The
pyscreenshot
module can be used to copy the contents of the screen to aPIL
image memory or file. You can install it usingpip
.Usage:
What did you try?
As the documentation for
ImageGrab
clearly states, the function has abbox
parameter, and:So, you only get the whole screen if you don't pass a
bbox
.Note that, although I linked to the Pillow docs (and you should be using Pillow), old-school PIL's docs say the same thing:
So, unless you're using a really, really old version of PIL (before 1.1.3, which I believe is more than a decade out of date), it has this feature.
You could use Python MSS.
From documentation to capture only a part of the screen:
1) Use pyscreenshot, ImageGrab works but only on Windows
2) Grab the image and box it, then save that image
3) Don't use ImageGrab.grab_to_file, it saves the full size image
4) You don't need to show the image with im.show if you just want to save a screenshot