Toying with C#
I am unable to return a point with this block of code always ends up returning Cursor position instead of position new point( x, y) Any help would be appreciated. I'm coding about 4 separate programs simply as a learning experience.
Problem isn't in get pixel so it is either in my for loop arguments or my return statements.
Code:
public Point FindPixel(Color ColorToFind)
{
Bitmap bitmapin = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
var gfxScreenshot = Graphics.FromImage(bitmapin);
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0,
Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
for (int y = 0; y < (Screen.PrimaryScreen.Bounds.Height; y++)
{
for (int x = 0; x < (Screen.PrimaryScreen.Bounds.Width; x++)
{
Color pixel = bitmapin.GetPixel(x, y);
if (pixel == ColorToFind)
{
return new Point(x, y);
}
}
}
return new Point(Cursor.Position.X, Cursor.Position.Y);
}
