Python MSS 스크린샷


설치하기

터미널에 아래와 같이 입력후 설치를 합니다.

python -m pip install mss

설치된 모듈이 정상적인지 확인합니다.

import  mss

이미지 처리를 위해서 이미지 처리 모듈을 설치 합니다.

python -m pip install Pillow

스크린샷 만들기

import mss

with mss.mss() as mss_instance:
    monitor_1 = mss_instance.monitors[1]capture
    screenshot = mss_instance.grab(monitor_1)

스크린샷 보기

from PIL import Image
import mss

with mss.mss() as mss_instance:
    monitor_1 = mss_instance.monitors[1]
    screenshot = mss_instance.grab(monitor_1)

    img = Image.frombytes("RGB", screenshot.size, screenshot.bgra, raw", "BGRX")  # Convert to PIL.Image
    img.show()

저장하기

import mss

output_filename = 'screenshot.png'

with mss.mss() as mss_instance:
    mss_instance.shot(output=output_filename)

File Object 로 저장

import io
from PIL import Image
import mss

bytes_io = io.BytesIO()

with mss.mss() as mss_instance:
    monitor_1 = mss_instance.monitors[1]
    screenshot = mss_instance.grab(monitor_1)

    img = Image.frombytes("RGB", screenshot.size, screenshot.bgra, "raw", "BGRX")
    img.save(bytes_io, "PNG")





© 2018. by brian jung

Powered by storm