Got problem with mss: mss.exception.ScreenShotError: gdi32.GetDIBits() failed

269 Views Asked by At

Now i'll show this code:

   ...
ScreenSizeX = 1600
ScreenSizeY = 900
with mss.mss() as sct: 
    monitor = {'top': 0, 'left': 0, 'width': ScreenSizeX, 'height': ScreenSizeY}

while True:
    img = np.array(sct.grab(monitor))
    ...

I run it and it show this error Traceback (most recent call last): File "D:\Users\totha\Downloads\Leonardo-main\Aimbot.py", line 20, in <module> img = np.array(sct.grab(monitor)) ^^^^^^^^^^^^^^^^^ File "D:\Python 3.11\Lib\site-packages\mss\base.py", line 90, in grab screenshot = self._grab_impl(monitor) ^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Python 3.11\Lib\site-packages\mss\windows.py", line 252, in _grab_impl raise ScreenShotError("gdi32.GetDIBits() failed.") mss.exception.ScreenShotError: gdi32.GetDIBits() failed.

1

There are 1 best solutions below

0
On

You get this error when you manually change the window size or when you loop with another window and use different window resolutions. I faced the same problem and solved it as follows.

As a solution:

Make every window or screen you will use the same size.

Issue link:

https://github.com/BoboTiG/python-mss/issues/135#issuecomment-568806443