简体   繁体   中英

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.

For example, in my laptop I have a resolution of 1920x1080 and I've set a 140% zoom in Win10. 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: 在此输入图像描述

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.

Found the solution on a Github thread . It has to do with the DPI of my laptop's screen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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