Is there a way to get the color of a pixel on the screen including the cursor with C#? Right now, this
//Gets color at location
public Color GetColorAt(Point location)
{
using (Graphics gdest = Graphics.FromImage(screenPixel))
{
using (Graphics gsrc = Graphics.FromHwnd(IntPtr.Zero))
{
IntPtr hSrcDC = gsrc.GetHdc();
IntPtr hDC = gdest.GetHdc();
int retval = BitBlt(hDC, 0, 0, 1, 1, hSrcDC, location.X, location.Y, (int)CopyPixelOperation.SourceCopy);
gdest.ReleaseHdc();
gsrc.ReleaseHdc();
}
}
return screenPixel.GetPixel(0, 0);
}
Will return the color of a pixel, but ignores the color of the cursor when doing so. So if I set the location to 500x500, pulled up a black picture, and then hovered the middle of my white mouse cursor at the 500x500 mark, the color returned will still be black and not white. Is there a way to get around this?