Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Imaging Library fails to grab whole screen

I am using PIL to grab a screen shot, but it is only capturing a part of the screen.

Here is a screen shot of my desktop

And this is what the program captures

As you can see, the screen has a good amount of space chopped off on the side and along the bottom. I tried to correct this by adjusting the size of the capture zone, but that just resulted in the extra areas just to be filled with black

I'm thinking that there is a limit to the maximum resolution that the library can capture, but I cant really find any documentation saying so.

Below is my code

import ImageGrab
import os
import time


def screenGrab():
    box = (0, 0, 1920, 1080)
    im = ImageGrab.grab(box)
    im.save(os.getcwd() + '\\screenshot_' + str(int(time.time())) + '.png', 'PNG')


def main():
    screenGrab()

if __name__ == '__main__':
    main()

Dose anyone know how to fix this issue or know why its happening?

like image 946
trumpet7347 Avatar asked Jun 23 '14 15:06

trumpet7347


2 Answers

There is a working workaround for this without fiddling with the OS settings. The solution is to use the following to make your program DPI aware on Windows :

from ctypes import windll
user32 = windll.user32
user32.SetProcessDPIAware()

Hope that helps

like image 140
josh Avatar answered Sep 28 '22 15:09

josh


I was having this problem too earlier today. The script would only capture pixels 0,0 - 1536,864. I recently switched to windows 8 and noticed that some programs seemed to be displayed at the incorrect resolution. After some searching I found a fix.

  • Go to your python directory (c:/python27/ for me)
  • Right click python.exe and select properties
  • Select the compatibility tab
  • Press the "Change settings for all users" button
  • Check the "Disable display scaling on high DPI settings" box
  • ImageGrab will now capture the entire resolution

I'll update if I find a universal fix, but I thought I'd post here since I searched for an hour or so and couldn't find a solution.

EDIT:

Universal fix

  • right click desktop
  • select "screen resolution"
  • click on "make text and other items larger or smaller"
  • check "let me choose one scaling level for all my displays"
  • select "smaller - 100%"

This will result is a smaller but sharper text and icons.

like image 36
blazeyja Avatar answered Sep 28 '22 14:09

blazeyja