Faster method of reading screen pixel in Python than PIL?

后端 未结 5 764
故里飘歌
故里飘歌 2020-12-13 22:28

Currently I\'m using a pixel reader via AutoItv3 to perform some actions in a program that is running direct X; A game. Right now the program works fine but as an exercise

5条回答
  •  温柔的废话
    2020-12-13 22:48

    It's an old question, but it ranks quite highly on Google when searching for Python screen grab methods, so I think it might be useful to mention that the ImageGrab module now supports grabbing a region of the screen:

    PIL.ImageGrab.grab(bbox=None)
    Parameters: bbox – What region to copy. Default is the entire screen.
    Returns:    An image
    

    http://pillow.readthedocs.io/en/3.1.x/reference/ImageGrab.html

    Expanding the scope slightly, there is now also a replacement for ImageGrab called pyscreenshot, that also saves some part of the screen to a or PIL/Pillow image. This module also works on Linux, unlike ImageGrab which is Windows and OS X only.

    import pyscreenshot as ImageGrab
    im=ImageGrab.grab(bbox=(10,10,510,510)) # X1,Y1,X2,Y2
    im.show()
    

    https://pypi.python.org/pypi/pyscreenshot

提交回复
热议问题