Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Take screenshots **quickly** from python

A PIL.Image.grab() takes about 0.5 seconds. That's just to get data from the screen to my app, without any processing on my part. FRAPS, on the other hand, can take screenshots up to 30 FPS. Is there any way for me to do the same from a Python program? If not, how about from a C program? (I could interface it w/ the Python program, potentially...)

like image 643
Claudiu Avatar asked Aug 14 '09 08:08

Claudiu


People also ask

How do I screenshot faster in Python?

Get the numpy representation of screenshot import mss import numpy as np with mss. mss() as sct: monitor = {"top": 160, "left": 160, "width": 160, "height": 135} img_array = np. array(sct. grab(monitor)) # Do whatever you want...

Can we take a screenshot using Python?

PIL is one of the most famous Python libraries for working with images and is widely used for image processing. It is not a surprise to expect the screenshot functionality included in it as well. Similarly to the pyautogui solution, PIL allows to take a screenshot using Python in three lines of code as well.

How do you take a screenshot of a page in Python?

You can take a screenshot of a webpage with the method get_screenshot_as_file() with as parameter the filename. The program below uses firefox to load a webpage and take a screenshot, but any web browser will do. The screenshot image will be stored in the same directory as your Python script.


1 Answers

If you want fast screenshots, you must use a lower level API, like DirectX or GTK. There are Python wrappers for those, like DirectPython and PyGTK. Some samples I've found follow:

  • PyGTK sample

  • Windows and DirectX samples

like image 190
Vinko Vrsalovic Avatar answered Oct 16 '22 15:10

Vinko Vrsalovic