I’m trying to find me a image on the screen. I have the image saved on my computer and loaded by using Image.FromFile().
I’m creating a screenshot of the screen using
var image = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
var gfx = Graphics.FromImage(image);
gfx.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
return image;
but now I have no idea how to search for the first image in the screen image.
I’ve search a bit on stackoverflow and found some answer but no where a proper example.
Since my C# skill aint the best I work better with a basic example which I can then understand and play with to learn more about it.
Can anyone provide me such a sample?
What you describe is known as template matching. You have a small image (the template) which is located somewhere in a larger image.
There is alot of information about algorithms for this, but i really recommend you to use a library instead.
OpenCV is a well known open source library for this and it’s really easy to use. OpenCV is written in C++ so it might be hard to use that in a C# environment. Luckily there is also a C# port called EmguCV, which is also free to use.
http://www.emgu.com/wiki/index.php/Main_Page