簡體   English   中英

是否可以通過X和Y坐標獲取屏幕上特定像素的顏色?

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

我想使用其XY坐標獲取Python中特定像素的顏色,這可能嗎?

如果有幫助,請在Windows中使用。

請參閱python標題下的http://rosettacode.org/wiki/Color_of_a_screen_pixel

他們給:

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)

使用適用於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