Click here to Skip to main content
15,902,874 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Hello programmers. I need a liitle Help in Windows Forms. I want to write a Code that returns true if Bitmap Image A is in Bitmap Image B. For Example : B=Screenshoot and A=little Part of Screenshot(Icon) . Programms return True if B contains A and returns False if it isn't. Have anyone Idea how to do this.

I have found a Code in Internet but havenn't understand how it works. Can someone explain ?

Here is a Code :

public class BitmapExtensions
        public bool Contains(this Bitmap template, Bitmap bmp)
            const int divisor = 4;
            const int epsilon = 10;

            ExhaustiveTemplateMatching etm = new ExhaustiveTemplateMatching(0.9f);

            TemplateMatch[] tm = etm.ProcessImage(new ResizeNearestNeighbor(template.Width / divisor, template.Height / divisor).Apply(template),
                                                  new ResizeNearestNeighbor(bmp.Width / divisor, bmp.Height / divisor).Apply(bmp));
            if (tm.Length == 1)
                Rectangle tempRect = tm[0].Rectangle;

                if(Math.Abs(bmp.Width / divisor - tempRect.Width) < epsilon && Math.Abs(bmp.Height / divisor - tempRect.Height) < epsilon)
                    return true;
            return false;
Updated 18-Sep-15 4:11am
F-ES Sitecore 18-Sep-15 10:02am    
Given you seemingly have no idea how to do this at all, I imagine a good first step would be to google "c# find one image inside another" and go through the many examples that already exist. If you are having problems implementing your chosen example you can ask a specific question about your specific problem.

Edit: The sample you posted is using a third party library to do the clever work. You'd need to look at the source of that library to find out how it is working
sreeyush sudhakaran 18-Sep-15 13:35pm    
It seems this is image processing project , to identify images you can use opencv like libraries
dave_bulac 18-Sep-15 14:25pm    
can you give me example of working with images in opencv ?
Gonzoox 18-Sep-15 15:13pm    
Google not working???
sreeyush sudhakaran 21-Sep-15 5:46am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900