So here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GandomTest
{
class Program
{
public static bool SearchPixel(string hexcode)
{
Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics graphics = Graphics.FromImage(bitmap as Image);
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
Color desiredPixelColor = ColorTranslator.FromHtml(hexcode);
for (int x = 0; x < SystemInformation.VirtualScreen.Width; x++)
{
for (int y = 0; y < SystemInformation.VirtualScreen.Height; y++)
{
Color currentPixelColor = bitmap.GetPixel(x, y);
if (desiredPixelColor == currentPixelColor)
{
Console.WriteLine("Color found!");
Thread.Sleep(10000);
return true;
}
else
{
Console.WriteLine("Not found");
continue;
}
}
}
return false;
}
static void Main(string[] args)
{
SearchPixel("#000000");
Console.ReadKey();
}
}
}
I was trying to loop the pixel recognition so as soon as the pixel is detected write something in console. The thing I do not know how can I make this work properly. I know this probably isn't the fastest way to do it but everytime I run it, and the specified color is on screen, the program does not detect it.