Jump to content

Pixelsearch with c#


hermherm
 Share

Recommended Posts

Hi again :)

So I got a problem with my pixelsearch function

I use it for a game, and in this game there appears a specific color

within 30 seconds but you never know exactly when it appears...it's randomly

so I use pixelsearch and a timer which lasts for 30 seconds

but after 10-15 seconds I got an exeption from pixelsearch (image below)

sure.. I can catch the exception, no problem... but pixelsearch wouln't search again for the color

So what can I do that he searches for the 30 seconds constantly without throwing exeptions

while(!timerout ) // timerout get's true if 30 seconds passed
    {
        searchs =PixelSearch (s_left, s_top,s_right,s_bottom, 1, 0x8A99E3, 20);
        bool found= System.Convert.ToBoolean(searchs);
        if(found)
        {
            break;
        }
        autoit.Sleep(10);
    }

Posted Image

and that is my pixesearch function

private int[] PixelSearch(int startX,int startY,int rangeX,int rangeY, int step,int color,int shade)
        {
            for(int x=startX;x<startX+rangeX;x+=step)
            {
                for(int y=startY;y<startY+rangeY;y+=step)
                {
                    if(autoit.PixelGetColor(x,y)==color) // if(autoit.PixelGetColor(x,y)==color)
                        return new int[]{x,y};
                }
            }
            throw new ApplicationException("PixelSearch: Failed to find the color ("+color.ToString()+")");
        }

Would be very nice if someon could help me :P

ty

Edited by hermherm
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...