Question Pixel Colors, take a pixel from the screen!

Apocalyptic

New member
Joined
Oct 9, 2010
Messages
4
Programming Experience
Beginner
Yeh I know it's so trivial but I'm trying to do it since a lot of time in VB 2005 Express Edition. Let me explain:

I need to make an easy output of a specific color on my whole screen.

For example: I have a Form with
-btnSearch
-txtX
-txtY
-lblColor


When I press 'btnSearch', it takes the coordinates (x,y) from my textboxes, and checks on the screen what color is it and writes it in the lblColor. The color must be written in hexadecimal, like "#FFFFFF".


Can someone help me to realize it? I think it's an easy code. I've tried to do it in this way:

btnSearch Event:

Dim Screen as ....HELP!

lblColor.Text = Screen.GetPixel(TextBox1.Text, TextBox2.Text)
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,519
Location
Norway
Programming Experience
10+

Apocalyptic

New member
Joined
Oct 9, 2010
Messages
4
Programming Experience
Beginner
OK, I've finished my project, and it works. But... It makes me lag because I used Timers. I'd like if you could suggest me where can I render my code simplier!

-What's the program's point?
1) I check a line on my screen with GETCOLOR: from (590,580) to (620,580), with Step "2". So it checks 15 different coordinates.
2) If it finds one of 3 colors on this coordinates, then LefClickDown activates.

The problem is that I've used a Timer with Interval "1"... (1000 = 1 second) so it's quite fast and in this way it produces frame lag!

Now I'll post a peace of code so you can see it and laugh on it:

peace of code from "Base" named form:
__________________________________________________
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "Start" Then
Button1.Text = "Stop"
Cross.Timer2.Start()
Else
Button1.Text = "Start"
Cross.Timer2.Stop()
Cross.Timer3.Stop()
End If

____________________________________________
peace of code from "Cross" named form:
____________________________________________

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
' In declare module, Public x As Integer = 590
If x = 620 Then
Timer2.Stop() 'the current one
Timer3.Start() 'the one under this one
Else

'x is variable... 15 times as I told before. Y is static.
MyColor = GetScreenPixel(New Point(x, 580))

htmlColor = ColorTranslator.ToHtml(MyColor)

'this are 3 colors I'm looking for in this interval of 15 coordinates
If htmlColor = "#FF2222" Or htmlColor = "F08B6B" Or htmlColor = "ED3931" Then
'there is an Event Sub, which presses mouse left button, but doesn't release it (Only MouseDown)
PerformMouseClick("LClick")
End If
x = x + 2
End If
End Sub

'This timer is inverted... it goes from x: 620 to x:590.... so my search style is like this: 1) ->>>>>> 2) <<<<<<- ... It goes and returns all the time.

Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
If x = 590 Then
Timer3.Stop()
Timer2.Start()
Else
MyColor = GetScreenPixel(New Point(x, 580))
htmlColor = ColorTranslator.ToHtml(MyColor)
If htmlColor = "#FF2222" Or htmlColor = "F08B6B" Or htmlColor = "ED3931" Then
PerformMouseClick("LClick")
End If
x = x - 2
End If
End Sub


NOW..... I need to know if I could remove timers and put everything on MouseHover Event (Hover searched Pixel Color). So when I move the mouse in every point of the screen, it makes this search.... And if it detects one of 3 colors, when the pointed Pixel is the one I'm searching for, then the LEFT MOUSE DOWN activates..... WHILE, when MouseLeave() [the searched pixel is no more pointed by the cursor, then LEFT MOUSE UP activates.

The problem is that MouseHover works only for the FORM... hover the form, and not hover the searching point which is out of the form..
 
Last edited:
Top Bottom