Color of a screen pixel: Difference between revisions

Content added Content deleted
(Don't copy entire screen (thanks to F# example))
Line 20: Line 20:
int h = Screen.PrimaryScreen.Bounds.Height;
int h = Screen.PrimaryScreen.Bounds.Height;


Bitmap img = new Bitmap(w, h);
Bitmap img = new Bitmap(1, 1);
Graphics g = Graphics.FromImage(img);
Graphics g = Graphics.FromImage(img);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(w, h));
g.CopyFromScreen(new Point(x, y), new Point(0, 0), new Size(1, 1));


Color color = img.GetPixel(x, y);</lang>
Color color = img.GetPixel(x, y);</lang>

=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
The C# example copies the entire screen into our private bitmap but that's unnecessary. All we need is the single pixel. Also, it doesn't appear that the bitmap and graphics object are being disposed of there. Other than that, this is essentially identical to that solution.
The C# example copies the entire screen into our private bitmap but that's unnecessary. All we need is the single pixel. Also, it doesn't appear that the bitmap and graphics object are being disposed of there. Other than that, this is essentially identical to that solution.