To capture specific rectangle form the screen use the following code
public Bitmap CaptureFromScreen(Rectangle rect)
{
Bitmap bmpScreenCapture = null;
if (rect == Rectangle.Empty)//capture the whole screen
{
rect = Screen.PrimaryScreen.Bounds;
}
bmpScreenCapture = new Bitmap(rect.Width,rect.Height);
Graphics p = Graphics.FromImage(bmpScreenCapture);
p.CopyFromScreen(rect.X,
rect.Y,
0, 0,
rect.Size,
CopyPixelOperation.SourceCopy);
p.Dispose();
return bmpScreenCapture;
}
To Get The color form a specific location use the function
public Color GetColorFromScreen(Point p)
{
Rectangle rect = new Rectangle(p, new Size(2, 2));
Bitmap map = CaptureFromScreen(rect);
Color c = map.GetPixel(0, 0);
map.Dispose();
return c;
}