Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PIL's ImageGrab is capturing at the wrong resolution

I'm trying to get a full screen (1920 x 1080) capture using this code. The saved images are only 1536 x 864 though.

solution: As Mark pointed out below, Windows has scaling which can be changed via Control Panel > Display (turn it all the way down).

from PIL import ImageGrab
import os
import time

def screenGrab():
    # snapshot of screen
    im = ImageGrab.grab()
    # saves in current work directory with name based on time of pic
    im.save(os.getcwd() + '\\full_snap__' + str(int(time.time()))
            + '.png', 'PNG')

def main():
    screenGrab()

if __name__ == '__main__':
    main()
like image 839
NoahLE Avatar asked Aug 23 '14 23:08

NoahLE


2 Answers

If you have your Display settings set to anything other than the "smaller" (100%) setting which is the default, Windows will tell your applications to render to a smaller area and then magnify the results as it puts it on the desktop. Evidently PIL has a bug caused by this setting, the capture is being cropped to the smaller size rather than the full desktop. The workaround is to be sure that your display settings are set to 100%.

like image 66
Mark Ransom Avatar answered Sep 27 '22 21:09

Mark Ransom


I manage to overcome this issue by adding registry key at

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

add a key with the path to your python.exe and pythonw.exe and in value set HIGHDPIAWARE

like so:

"C:\Users\Greg\Anaconda3\python.exe"="HIGHDPIAWARE" "C:\Users\Greg\Anaconda3\pythonw.exe"="HIGHDPIAWARE"

then everythings should be ok :)

credit to that scipt: Marking Your Python Program as High DPI Aware Seemlessly Windows

like image 42
Gregy8 Avatar answered Sep 27 '22 20:09

Gregy8