This question already has answers here:
Python Imaging Library fails to grab whole screen
                                
                                    (2个答案)
                                
                        
                                在10个月前关闭。
            
                    
我试图使用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()就能捕获他们的屏幕。

任何帮助,将不胜感激!

最佳答案

当我尝试遵循本教程https://code.tutsplus.com/tutorials/how-to-build-a-python-bot-that-can-play-web-games--active-11117时,在PIL上也遇到了同样的问题。

为了解决这个问题

->转到Python安装目录,然后右键单击python.exe

->属性->兼容性选项卡->选中“在高DPI设置上禁用显示比例缩放”。

对pythonw.exe重复相同的过程。希望你的问题解决。请告诉我。

07-24 09:51
查看更多