forked from BoboTiG/python-mss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpil.py
More file actions
25 lines (19 loc) · 741 Bytes
/
Copy pathpil.py
File metadata and controls
25 lines (19 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss.
PIL example using frombytes().
"""
from PIL import Image
import mss
with mss.MSS() as sct:
# Get rid of the first, as it represents the "All in One" monitor:
for num, monitor in enumerate(sct.monitors[1:], 1):
# Get raw pixels from the screen
sct_img = sct.grab(monitor)
# Create the Image
img = Image.frombuffer("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX", 0, 1)
# The same, but less efficient:
# img = Image.frombuffer('RGB', sct_img.size, sct_img.rgb, 'raw', 'RGB', 0, 1)
# And save it!
output = f"monitor-{num}.png"
img.save(output)
print(output)