Exemplo n.º 1
0
def getPixelColor(*args):
    # the result will be such as Color [A=255, R=107, G=107, B=107].
    if len(args) == 2:
        x = args[0]
        y = args[1]

    if isinstance(args[0], Point):
        x = args[0].X
        y = args[0].Y

    hdc = User32.GetDC(IntPtr.Zero)
    pixel = GDI32.GetPixel(hdc, x, y)
    User32.ReleaseDC(IntPtr.Zero, hdc)
    result = Color.FromArgb(
        pixel & 0x000000FF,  # R
        # First And operation
        (pixel & 0x0000FF00) >> 8,  # G
        (pixel & 0x00FF0000) >> 16)  # B
    return result