2

I was trying to capture my screen image using PIL.ImageGrab.grab(). Here is my problem -- When I use the code below, img is only the upper left part of my screen.

from PIL import ImageGrab
img = ImageGrab.grab()

Use win32api.GetSystemMetrics() to find out my screen size.

> GetSystemMetrics(0)
Out[6]: 1280

> GetSystemMetrics(1)
Out[7]: 720

I then used ImageGrab.grab((0,0,1280,720)), and still got the upper left part of my screen! Desperately, I called ImageGrab.grab((0,0,1400,900)), and the output is the same partial image with a black frame in its lower right area...

I have no idea what happened. It seems other guys are able to capture their screen by simply call ImageGrab.grab().

Any help would be appreciated!

H.Zhao Zhang
  • 33
  • 1
  • 6

2 Answers2

3

As josh pointed out, 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()

by josh

Elijas Dapšauskas
  • 909
  • 10
  • 25
2

I faced the same problem on PIL when I was trying to follow this tutorial https://code.tutsplus.com/tutorials/how-to-build-a-python-bot-that-can-play-web-games--active-11117.

To solve this problem,

-> Goto Python installed directory and Right-click on python.exe

-> Properties -> Compatibility tab -> check 'Disable display scaling on high DPI settings'.

Repeat the same procedure for pythonw.exe. Hope your problem solved. Please let me know.

Harun Diluka Heshan
  • 1,155
  • 2
  • 18
  • 30