Pixel Detection If True Then, Else , End If

I am looking for some help with understanding how Pixel detection can work in Visual Basic. I am looking for some code help, I want to detect some pixel's on the screen to check if they are true or not. My goal is to make a program that will use google voice, text me when a slot opens up on training that I am doing in a game. This helps me keep an idea on the trainings completed, and what new once I will have to add. I use visual basic 2010 version with Visual Studio. I have this working in AutoIt, but just want to get it working in vb, so I can cut down on how many program im using current to do this, and have just 1 program that can handle it.

Wish it were as simple as:

Private Sub PixelCheck()
'coord to check (x,y)
     if pixel color = FFFFF9 then
              'run this code
     Else
              'the value was false we need to do this instead
     End if
End Sub

Open in new window

LVL 1
Jack_JonesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tom BeckCommented:
You can get the RGB value of a given pixel with something like this:

Dim c As Color = myBitmap.GetPixel(pos.x, pos.y)
0
Jack_JonesAuthor Commented:
TommyBoy, how could I utilize that in an if statment like my wish it were a simple as this code lol.
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Jack_JonesAuthor Commented:
CodeCruser,

 The first example looks really cool, only thing is I don't seen an autoredraw value for the picturebox1 in visual basic 2010. Any suggestions on that?
0
Jack_JonesAuthor Commented:
I should note, I am already able to get the pixelcolor in hex code, not sure if that helps.
0
CodeCruiserCommented:
Where is autoredraw? What happens if you comment that out?
0
Jack_JonesAuthor Commented:
I have the hex color of the pixel, and the x,y coords already. My hope is to check the Hexcolor @ x,y location and if true then perform an action else do this type of thing.
0
Tom BeckCommented:
I'm not quite understanding what you are trying to do. Are you getting the pixel color from a particular position on the screen of a web page (problematic), or from the css value of a particular html element from the stylesheet (do-able), or from an image that's loaded into say a panel your vb program (most accurate)?

When you say "I have the hex color of the pixel" do you mean you have the color of the the pixel you want to compare against an unknown pixel or do you mean I have already captured the unknown pixel and know it's hex value and I just need a way to compare the two pixels?
0
Jack_JonesAuthor Commented:
I would say the statment:

" I have already captured the unknon pixel and know it's hex value and I just need a way to compare the two pixels. "

This would give me a true / false output to work with. the IF / Else Statement. So I guess take the unknown at x,y, and compare it to the known one for a true / false value.
0
Tom BeckCommented:
So...you have already captured the unknon pixel and know it's hex value?

And my first question?
0
Jack_JonesAuthor Commented:
I only have the value for the know hexcolor pixel location, what I need to do is find if the value in the (x,y) is true / false.

Say for example it's a white dot, and that white dot changes to blue. What I want is to detect that the white dot, changed to blue and if it did then execute this code or if it's false do this code instead.
0
Tom BeckCommented:
>>What I want is to detect that the white dot...

On a web page then? If so, I think you would first have to find the white/blue area on the page. A lot of factors can affect the pixel location, resolution, scroll position, zoom level, window size and position. I assuming you want this to happen programatically while you are not present to "pick" the pixel out with your cursor.
0
Jack_JonesAuthor Commented:
Yeah, thats why I was hopeing to use and IF / ELSE.  But you deff understand what im trying to say / do now ;) lol.

0
Tom BeckCommented:
The if/else is the least of your troubles. First you've got to figure out how you are going to get the color of that pixel. I'm not sure how you could accurately pin-point the position on rendered page or from the html. You might be better off pulling it from the css of the page if it's a background color fill and not an image.  Actually, it may be easier to find out just what is different on the page with the blue pixel vs. the white pixel. Maybe there's a word that changes that you could search for in the html like "Ok, that training complete" and you could look for the "Ok".

Maybe @CodeCruiser has an idea.
0
Jack_JonesAuthor Commented:
For an example,

 I have a program that gives me mousex, y and the color.

So far what it will do is tell me Coordinates 767, 86 Color: FFFFF9

I want to check the above Coordinates, for Color: FFFFF9 else do this instead.
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Your (x, y) coordinates, are they absolute screen coords?...or relative to the upper left of a specific window?
0
Jack_JonesAuthor Commented:
They are screen coords.
0
Tom BeckCommented:
Therein lies the problem with that method. There has to be a better way to detect when the page has updated to the blue than to look for the color of the button. Can yo share an example of the page with white and another with blue?
0
Jack_JonesAuthor Commented:
I could sendkey({F5}) to refreash the page?
0
Jack_JonesAuthor Commented:
so if true sendkey({F5}) else thread.sleep(5000)
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
I assume you'll be polling with a timer?

Here's how you can check if the color at an absolute screen coordinate is an exact specific color:
Private Function IsColorAt(ByVal pt As Point, ByVal clr As Color) As Boolean
        Dim bmp As New Bitmap(1, 1)
        Using G As Graphics = Graphics.FromImage(bmp)
            G.CopyFromScreen(pt, New Point(0, 0), bmp.Size)
        End Using
        Return bmp.GetPixel(0, 0).Equals(clr)
    End Function

Open in new window

0
Jack_JonesAuthor Commented:
So this function I would have to do the following with:

If IsColorAt() = True Then
 thread.sleep(3000)
else
 msgbox("Changed, site updated!")
endif

Private Function IsColorAt(ByVal pt As Point, ByVal clr As Color) As Boolean
        Dim bmp As New Bitmap(1, 1)
        Using G As Graphics = Graphics.FromImage(bmp)
            G.CopyFromScreen(pt, New Point(x coordinate, y coordinate), bmp.Size) ' x,y to check?
        End Using
        Return bmp.GetPixel(0, 0).Equals(clr)
    End Function

Open in new window

0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
You had mentioned this combination previously:

    Coordinates 767, 86 Color: FFFFF9

Convert the hex color to a .Net Color and pass that along with the coords to the function:

    Dim pt As New Point(767. 86)
    Dim clr As Color = ... not sure how you convert that ...  (not a web guy!)

    If IsColorAt(pt, clr) = True Then
0
Jack_JonesAuthor Commented:
ok it's a RGB color, sorry for calling it hex was my mistake.  Not sure if that changes anything.
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
You might want:

    Dim clr As Color = System.Drawing.ColorTranslator.FromHtml("#FFFFF9")

*Not sure if that's right or not.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jack_JonesAuthor Commented:
Tested and works like a OMG CHARM! You are the MAN, thank you so much for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.