5

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?

trumpet7347
  • 67
  • 1
  • 5
  • Have you tried to not supply the box parameters? From the documentation, if you don't supply any parameters the entire screen is copied automatically. – hazzey Jun 23 '14 at 19:07
  • @hazzey Yes, when I dont supply the parameters, it results in the second screen shot, when I add the parameters, it resulst with the same screen shot, just with black filling in the new area. http://i.imgur.com/dUjP9vx.png – trumpet7347 Jun 23 '14 at 19:18
  • I wonder if it has to do with having "Aero Glass" turned on. You could try turning that off and see if it changes anything. – hazzey Jun 24 '14 at 00:13
  • @hazzey Running Windows 8, so no Aero Glass. Went ahead and tried just switching to classic style though, no change. – trumpet7347 Jun 24 '14 at 13:17

2 Answers2

11

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

josh
  • 156
  • 1
  • 11
10

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.

blazeyja
  • 116
  • 1
  • 3