Is it possible to get the color of a particular pixel on the screen with it's X and Y coordinates?

后端 未结 1 416
栀梦
栀梦 2021-01-16 19:48

I would like to get the color of a particular pixel in Python using its X Y coordinates, is this possible?

This is in Windows, if it makes a difference.

相关标签:
1条回答
  • 2021-01-16 20:11

    See http://rosettacode.org/wiki/Color_of_a_screen_pixel under the heading for python

    they give:

    def get_pixel_colour(i_x, i_y):
        import win32gui
        i_desktop_window_id = win32gui.GetDesktopWindow()
        i_desktop_window_dc = win32gui.GetWindowDC(i_desktop_window_id)
        long_colour = win32gui.GetPixel(i_desktop_window_dc, i_x, i_y)
        i_colour = int(long_colour)
        return (i_colour & 0xff), ((i_colour >> 8) & 0xff), ((i_colour >> 16) & 0xff)
    
    print get_pixel_colour(0, 0)
    

    which uses Python Extensions for Windows which is available for python 2.3 to 3.1 at http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/

    0 讨论(0)
提交回复
热议问题