How to get pixel color from another programming by handle?? what wrong with my code?

0

How to get pixel color from another programming by handle?? what wrong with my code?

    [DllImport("user32.dll")]
    static extern IntPtr GetDC(IntPtr hwnd);

    [DllImport("user32.dll")]
    static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);

    [DllImport("gdi32.dll")]
    static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);

    static public System.Drawing.Color GetPixelColor(int x, int y)
    {
        IntPtr hdc = GetDC((IntPtr)2890812);
        uint pixel = GetPixel(hdc, x, y);
        ReleaseDC(IntPtr.Zero, hdc);
        System.Drawing.Color color = System.Drawing.Color.FromArgb((int)(pixel & 0x000000FF),
                     (int)(pixel & 0x0000FF00) >> 8,
                     (int)(pixel & 0x00FF0000) >> 16);
        return color;
    }

Returning is white color always.

2890812 is decimal Handle of another program from Spy++.

c#
gdi
handle
user32
asked on Stack Overflow Sep 20, 2017 by Kittinun Pongsukjai • edited Sep 20, 2017 by Kittinun Pongsukjai

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0