在百分比中使用 BBOX 选项而不是绝对像素 - PyScreenShot Python

Use BBOX Option In Percentage Instead Of Absolute Pixel - PyScreenShot Python

PyScreenShot 的 grab() 功能上的 BBOX 选项能够收集屏幕的一个区域,这很棒。

是否可以使用绝对百分比值来做同样的事情?使用像素值的问题是在不同分辨率的不同显示器上,抓取的图像会有所不同。

所以不要说

im = ImageGrab.grab(bbox=(100,100,500,500))

如果屏幕是 1920x1080 或任何其他分辨率,我总是可以获得相同的区域,独立的

是不是您要找的东西?

import mss
# import mss.tools


with mss.mss() as sct:
    monitor = sct.monitors[1]
    left = monitor['left'] + monitor['width'] * 5 // 100  # 5% from the left
    top = monitor['top'] + monitor['height'] * 5 // 100  # 5% from the top
    right = left + 400  # 400px width
    lower = top + 400  # 400px height
    box = (left, top, right, lower)
    im = sct.grab(box)
    # mss.tools.to_png(im.rgb, im.size, 'screenshot.png')