Taking Screen shots of specific size

后端 未结 5 446
庸人自扰
庸人自扰 2021-01-03 03:26

What imaging modules for python will allow you to take a specific size screenshot (not whole screen)? I have tried PIL, but can\'t seem to make ImageGrab.grab() select a sma

5条回答
  •  梦毁少年i
    2021-01-03 04:24

    You could use Python MSS.

    From documentation to capture only a part of the screen:

    import mss
    import mss.tools
    
    
    with mss.mss() as sct:
        # The screen part to capture
        monitor = {"top": 160, "left": 160, "width": 160, "height": 135}
        output = "sct-{top}x{left}_{width}x{height}.png".format(**monitor)
    
        # Grab the data
        sct_img = sct.grab(monitor)
    
        # Save to the picture file
        mss.tools.to_png(sct_img.rgb, sct_img.size, output=output)
        print(output)
    

提交回复
热议问题