ScarecrowBS 0 Newbie Poster

Hi there, I currently have a code that will search for a bitmap in a screenshot taken by this program, however, the bitmap exists three times in the screenshot and I want it to click the second time it finds it.

Is there any way to do this? A lot of thanks in advance...

Code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;


    private Bitmap Screenshot()
    {

        Bitmap bmpScreenShot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);


        Graphics g = Graphics.FromImage(bmpScreenShot);


        g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);


        return bmpScreenShot;

    }

            private bool FindBitmap(Bitmap BmpNeedle, Bitmap BmpHaystack, out Point location)
    {
        for (int outerX = 0; outerX < BmpHaystack.Width - BmpNeedle.Width; outerX++)
        {
            for (int outerY = 0; outerY < BmpHaystack.Height - BmpNeedle.Height; outerY++)
            {

                for (int innerX = 0; innerX < BmpNeedle.Width; innerX++)
                {
                    for (int innerY = 0; innerY < BmpNeedle.Height; innerY++)
                    {
                        Color cNeedle = BmpNeedle.GetPixel(innerX, innerY);
                        Color cHaystack = BmpHaystack.GetPixel(innerX + outerX, innerY + outerY);

                        if (cNeedle.R != cHaystack.R || cNeedle.G != cHaystack.G || cNeedle.B != cHaystack.B)
                        {
                            goto notFound;
                        }
                    }

                }
                location = new Point(outerX, outerY);
                return true;


            notFound:
                continue;

            }
        }
        location = Point.Empty;
        return false;
    }

    public void findImage()
    {
        Bitmap bmpScreenshot = Screenshot();
        Point location;
        bool success = FindBitmap(Properties.Resources.xxx, bmpScreenshot, out location);
    }

Don't know if that really helps, all I want it to do is click the second time it finds the bitmap.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.