public Color[] getColorsAt(Point location, Point size) { Bitmap screenPixel = new Bitmap(size.X, size.Y, PixelFormat.Format32bppArgb); using (Graphics gdest = Graphics.FromImage(screenPixel)) { using (Graphics gsrc = Graphics.FromHwnd(IntPtr.Zero)) { IntPtr hSrcDC = gsrc.GetHdc(); IntPtr hDC = gdest.GetHdc(); int retval = NativeImport.BitBlt(hDC, 0, 0, (size.X), (size.Y), hSrcDC, location.X - (size.X), location.Y - (size.Y), (int)CopyPixelOperation.SourceCopy); gdest.ReleaseHdc(); gsrc.ReleaseHdc(); } } List <Color> cols = new List <Color>(); for (int x = 0; x < screenPixel.Width; x++) { for (int y = 0; y < screenPixel.Height; y++) { cols.Add(screenPixel.GetPixel(x, y)); } } return(cols.ToArray()); }
public Color GetColorAt(Point location) { Bitmap screenPixel = new Bitmap(1, 1, PixelFormat.Format32bppArgb); using (Graphics gdest = Graphics.FromImage(screenPixel)) { using (Graphics gsrc = Graphics.FromHwnd(IntPtr.Zero)) { IntPtr hSrcDC = gsrc.GetHdc(); IntPtr hDC = gdest.GetHdc(); int retval = NativeImport.BitBlt(hDC, 0, 0, 1, 1, hSrcDC, location.X, location.Y, (int)CopyPixelOperation.SourceCopy); gdest.ReleaseHdc(); gsrc.ReleaseHdc(); } } return(screenPixel.GetPixel(0, 0)); }