为什么不能 ImageGrab.grab 捕获整个屏幕?
Why cannot ImageGrab.grab capture the whole screen?
我正在尝试使用 PIL.ImageGrab.grab() 捕获我的屏幕图像。
这是我的问题——当我使用下面的代码时,img
只是我屏幕的左上部分。
from PIL import ImageGrab
img = ImageGrab.grab()
使用 win32api.GetSystemMetrics()
找出我的屏幕尺寸。
> GetSystemMetrics(0)
Out[6]: 1280
> GetSystemMetrics(1)
Out[7]: 720
然后我用了ImageGrab.grab((0,0,1280,720))
,我的屏幕仍然是左上角!无奈之下,我调用了ImageGrab.grab((0,0,1400,900))
,输出的是同一张局部图,右下角有黑框...
我不知道发生了什么。似乎其他人只需调用 ImageGrab.grab()
.
就可以捕获他们的屏幕
如有任何帮助,我们将不胜感激!
当我尝试按照本教程进行操作时,我在 PIL 上遇到了同样的问题 https://code.tutsplus.com/tutorials/how-to-build-a-python-bot-that-can-play-web-games--active-11117。
为了解决这个问题,
-> 转到 Python 安装目录并在 python.exe
上 Right-click
-> 属性 -> 兼容性选项卡 -> 检查 'Disable display scaling on high DPI settings' .
对 pythonw.exe 重复相同的步骤。希望你的问题得到解决。请告诉我。
如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()
来自 josh
我正在尝试使用 PIL.ImageGrab.grab() 捕获我的屏幕图像。
这是我的问题——当我使用下面的代码时,img
只是我屏幕的左上部分。
from PIL import ImageGrab
img = ImageGrab.grab()
使用 win32api.GetSystemMetrics()
找出我的屏幕尺寸。
> GetSystemMetrics(0)
Out[6]: 1280
> GetSystemMetrics(1)
Out[7]: 720
然后我用了ImageGrab.grab((0,0,1280,720))
,我的屏幕仍然是左上角!无奈之下,我调用了ImageGrab.grab((0,0,1400,900))
,输出的是同一张局部图,右下角有黑框...
我不知道发生了什么。似乎其他人只需调用 ImageGrab.grab()
.
如有任何帮助,我们将不胜感激!
当我尝试按照本教程进行操作时,我在 PIL 上遇到了同样的问题 https://code.tutsplus.com/tutorials/how-to-build-a-python-bot-that-can-play-web-games--active-11117。
为了解决这个问题,
-> 转到 Python 安装目录并在 python.exe
上 Right-click-> 属性 -> 兼容性选项卡 -> 检查 'Disable display scaling on high DPI settings' .
对 pythonw.exe 重复相同的步骤。希望你的问题得到解决。请告诉我。
如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()
来自 josh