使用 Python 螢幕截圖 示範

安裝套件:
    
pip install mss
    

截取整個螢幕,儲存為 png 檔案:
    
import mss

with mss.mss() as sct:
    filename = sct.shot(output="screenshot.png")
    

截取螢幕指定區域,儲存為 png 檔案:
    
import mss

with mss.mss() as sct:
    region = {"top": 100, "left": 100, "width": 300, "height": 200}
    screenshot = sct.grab(region)
    mss.tools.to_png(screenshot.rgb, screenshot.size, output="partial_screenshot.png")

    

文章撰寫中...請稍後...

參考資料:

留言