[Python] getpixel() OR ImageGrab.grab() any other way?

Discussão em 'Python' iniciado por Stack, Abril 28, 2025.

  1. Stack

    Stack Membro Participativo

    python 2.7.18 , win10

    Python 3.10 Python 3.11

    I am trying to obtain an arbitery pixel's rgb (e.g top left corner 0,0). It doesnt need to be my mouse current position.

    Not sure about how does it work? screenshot the current screen and save it to an image then PIL to edit it? Or assign a variable for somewhere temp storage then read the rgb directly? Sorry, I am new and dont understand how does it work in python. (I also read an image that is composed of just an number array in numpy/opencv).

    There are some other questions Where does it store after taking a screenshot if no var assigned? Furthermore, is python like matlab? For example, "ans" is used to store the last executed command. Alternatively, "_" can only be used in IDE for last executable.

    Many thanks

    Tried: Method 1 using PIL/pillow

    PIL.ImageGrab.grab().load()[0,0]


    Method 2 using pyautogui

    im.getpixel((0,0))
    pyautogui.getpixel(0,0)

    Continue reading...

Compartilhe esta Página