I'm trying to scan my whole screen for a particular color, after that I will check if the color is found or not. However the process using Bitmap
and GetPixel
seems to be taking forever. I heard of something that I can use which us Bitlock
with Bitmap
, but I couldn't figure out how I can Implement it in my code.
Here it is my code that I'm using to scan my screen:
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace ConsoleApp1
{
internal class Program
{
public static Point location = new Point(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
static void Main(string[] args)
{
for (int x = 0; x < location.X; x++)
{
for (int y = 0; y < location.Y; y++)
{
Console.WriteLine(GrabColor(x,y));
}
Thread.Sleep(1000);
}
}
public static Color GrabColor(int x, int y)
{
using (var bitmap = new Bitmap(1,1))
{
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.CopyFromScreen(new Point(x,y), new Point(0,0), new Size(1,1));
}
return bitmap.GetPixel(0, 0);
}
}
}
}