简体   繁体   English

如果操作系统应用了缩放系数,则ImageGrab / pyscreenshot不会捕获全屏

[英]ImageGrab/pyscreenshot doesn't capture full screen if zoom-factor is applied by OS

I was messing around for fun with ImageGrab and I noticed that if you have set a custom zoom-factor in your OS, if you grab a full-screen image a portion of the capture will be black. 我在使用ImageGrab时很开心,我注意到如果你在操作系统中设置了自定义缩放系数,如果你抓住全屏图像,捕获的一部分将是黑色的。

For example, in my laptop I have a resolution of 1920x1080 and I've set a 140% zoom in Win10. 例如,在我的笔记本电脑中,我的分辨率为1920x1080,我在Win10中设置了140%的变焦。 If I grab a fullscreen, here's the result: 如果我抓一个全屏,这是结果:
在此输入图像描述

on the other hand, when the OS zoom is defaulted t0 100%, this is the correct fullscreen: 另一方面,当操作系统缩放默认为100%时,这是正确的全屏: 在此输入图像描述

The code I use is very basic, I'll show it just for completeness: 我使用的代码非常基本,我只是为了完整性而展示它:

from PIL import ImageGrab as ig
from pynput.mouse import Button, Controller
from pynput.keyboard import Key
from pynput import keyboard

def onpress(k):
    if k == keyboard.Key.esc:
        # break if esc is pressed
        return False
    else:
        img= ig.grab()
        img.save('screenshot.png')

with keyboard.Listener( on_press= onpress) as listener:
    listener.join()

I've noticed by logging the mouse position that when the screen is set at 140% zoom, the borders are at 0,0 - 1374,738 approximately. 我注意到通过记录鼠标位置,当屏幕设置为140%缩放时,边框大约为0,0 - 1374,738。

Found the solution on a Github thread . Github线程上找到了解决方案。 It has to do with the DPI of my laptop's screen. 它与笔记本电脑屏幕的DPI有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM