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
27 lines (21 loc) · 737 Bytes
/
pil.py
File metadata and controls
27 lines (21 loc) · 737 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
26
27
# coding: utf-8
"""
This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss
PIL example using frombytes().
"""
import mss
from PIL import Image
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.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX")
# The same, but less efficient:
# img = Image.frombytes('RGB', sct_img.size, sct_img.rgb)
# And save it!
output = "monitor-{}.png".format(num)
img.save(output)
print(output)