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...)
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...
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With