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!
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With