Exemple #1
0
def ScreenCapture(x, y, width, height):

    from UnmanagedCode import User32, GDI32
    from System.Drawing import Bitmap, Image

    hdcSrc = User32.GetWindowDC(User32.GetDesktopWindow())
    hdcDest = GDI32.CreateCompatibleDC(hdcSrc)
    hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height)
    GDI32.SelectObject(hdcDest, hBitmap)

    # 0x00CC0020 is the magic number for a copy raster operation
    GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, x, y, 0x00CC0020)
    result = Bitmap(Image.FromHbitmap(hBitmap))
    User32.ReleaseDC(User32.GetDesktopWindow(), hdcSrc)
    GDI32.DeleteDC(hdcDest)
    GDI32.DeleteObject(hBitmap)
    return result
Exemple #2
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