Quickly getting the color of some pixels on the screen in Python on Windows 7

前端 未结 4 921
说谎
说谎 2020-12-04 22:44

I need to get the color of some pixels on the screen or from the active window, and I need to do so quickly. I\'ve tried using win32gui and ctypes/

4条回答
  •  自闭症患者
    2020-12-04 23:20

    This is better than using getpixel all the time and works faster.

    import ImageGrab
    
    px = ImageGrab.grab().load()
    for y in range(0, 100, 10):
        for x in range(0, 100, 10):
            color = px[x, y]
    

    Reference: Image.load

提交回复
热议问题