I want to compare the color of the pixel in the middle of the screen in realtime to colors of a picture, and start a certain action when they overlap.
The Problem is that the pictures I want to compare the color with have way too many different colors and nuances, giving them each a different color code.
As a result, it is nearly impossible to get an accurate and consistent result without listing hundreds or thousands of colors for comparison (which would probably make the code really slow).
This is what I got until now, I have no idea how to solve this basic problem. The rest of the code is probably also pretty bad, so sorry; I´m really new to programming. Thanks for every answer!
static void Main(string[] args)
{
while (true)
{
List<string> givenList = new List<string> { "#FEFEFE", "#000000" };
//insert as many colors as you want, here white and black
Bitmap bitmap = new Bitmap(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
Graphics graphics = Graphics.FromImage(bitmap as Image);
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
Color middleCol = bitmap.GetPixel(SystemInformation.VirtualScreen.Width / 2, SystemInformation.VirtualScreen.Height / 2); //get the color value of only the middle Pixel and turn it into a string, so it can be compared to the list
string currentColor = ColorTranslator.ToHtml(middleCol);
Console.WriteLine("Current:" + currentColor);
Thread.Sleep(50);
foreach (string s in givenList) //do a certain action if the values overlap
{
if(s == currentColor)
{
//do whatever
}
}
}
}