简体   繁体   English

是否可以通过X和Y坐标获取屏幕上特定像素的颜色?

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

I would like to get the color of a particular pixel in Python using its XY coordinates, is this possible? 我想使用其XY坐标获取Python中特定像素的颜色,这可能吗?

This is in Windows, if it makes a difference. 如果有帮助,请在Windows中使用。

See http://rosettacode.org/wiki/Color_of_a_screen_pixel under the heading for python 请参阅python标题下的http://rosettacode.org/wiki/Color_of_a_screen_pixel

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/ 使用适用于Windows的Python扩展程序,扩展程序适用于python 2.3至3.1, 网址http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM