问题
I saw that post (that is really helpful : Take a screenshot via a python script. [Linux]) about taking a screenshot from python. It works well but I'd like to have the same behavior as gnome-screenshot : having the possibility to choose between :
- Capturing the whole desktop
- Capturing an active window
- Capturing an area
Is there a way to do this in python, or, eventually, to use the gnome-screenshot application to do it, and then getting the file ?
I tried to find the perfect command line for gnome-screenshot to be launched without asking where to save the screenshot after by giving the path at the call, but I can't find it.
Thanks for your help!
回答1:
If you are not limited to using using gnome-screenshot specifically, ImageMagick's import
command can save directly to file without an interactive prompt.
See here for details: http://www.imagemagick.org/script/import.php
In addition to the command line interface, there is also a Python API.
回答2:
I have a wrapper project (pyscreenshot) for scrot, imagemagick, pyqt, wx and pygtk. If you have one of them, you can use it. Capturing an active window is missing.
Install:
easy_install pyscreenshot
Example:
import pyscreenshot as ImageGrab
# fullscreen
im=ImageGrab.grab()
im.show()
# part of the screen
im=ImageGrab.grab(bbox=(10,10,500,500))
im.show()
# to file
ImageGrab.grab_to_file('im.png')
回答3:
Using gnome-panel-screenshot you can choose to pick just the window:
http://manpages.unixforum.co.uk/man-pages/unix/solaris-10-11_06/1/gnome-panel-screenshot-man-page.html
I found another page that has a lot of different ways to take a screenshot from the command line:
http://tips.webdesign10.com/how-to-take-a-screenshot-on-ubuntu-linux
Most of those quick tips on that page don't show how to narrow it to the window or an area, but more investigation into them will reveal the command line parameters needed.
来源:https://stackoverflow.com/questions/4921954/taking-screenshot-from-a-python-script-by-selecting-the-area