Results 1 to 17 of 17

Thread: [SOLVED] Conditional with Pixel Color?

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Question [SOLVED] Conditional with Pixel Color?

    Hello

    I would make this:

    Code:
    If (Coords) = FFF0F0F0 Then
         .......
    Else
         .....
    End If
    But i don't have any idea about how can i make this.

    Thanks and sorry my enlgish errors.
    Last edited by pguti19; Apr 26th, 2013 at 01:25 PM.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,386

    Re: Conditional with Pixel Color?

    Create a bitmap that represents your screen, then use Bitmap.GetPixel to get the color of a specific coordinate. To check if the color matches your html color code, use ColorTranslator.FromHtml.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Conditional with Pixel Color?

    You must commit whatever you're scanning to a Bitmap first (if it's a form background image or similar then you already have that step done).

    If bmp.GetPixel(x, y) = Color.FromArgb(&HFF, &HF0, &HF0, &HF0) Then
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: Conditional with Pixel Color?

    I have a bad - medium level in VB and i don't know how to manage Libs. I need some libs?

    The color is in a Windows (Chrome).

    How can i scan it?

    Thanks a lot

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,386

    Re: Conditional with Pixel Color?

    Quote Originally Posted by pguti19 View Post
    How can i scan it?
    Refer to post #2.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: Conditional with Pixel Color?

    I think that i didn't say good.

    I select a coords (X=100 Y=900 for example) and If this point is color #FF43523 Then...
    Bitmap.GetPixel scan all scren, or a image.

    It's the same for my question?

  7. #7
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,386

    Re: Conditional with Pixel Color?

    Did you read the documentation on Bitmap.GetPixel?
    Gets the color of the specified pixel in this Bitmap.
    That's why in post #2 I suggest to create a bitmap that represents your form, then use Bitmap.GetPixel to get a color of the specified pixel.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  8. #8

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: Conditional with Pixel Color?

    Sorry if i'm saying nonsenses, but i never manage this topic.

    With Bitmap.GetPixel I need say one file:

    Dim myBitmap As New Bitmap("grapes.jpg")
    Dim pixelColor As Color = myBitmap.GetPixel(50, 50)
    I need that the bold text will be my screen. How can i make this?

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: Conditional with Pixel Color?

    I have this code:

    Dim myBitmap As New Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height)
    Dim something As Color = myBitmap.GetPixel(50, 50)
    Dim something1 As Color = TextBox3.BackColor
    If something = TextBox3.BackColor Then
    TextBox3.Text = ":-D"
    Else
    TextBox3.Text = "D-:"
    End If
    But how can I tell VB the coords that I want get pixel?

  10. #10
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Conditional with Pixel Color?

    Dim something As Color = myBitmap.GetPixel(50, 50)

    There's the co-ordinates x,y. You change them as you wish.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  11. #11

    Re: Conditional with Pixel Color?

    I...think he wants a screenshot to be the bitmap?

  12. #12

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: Conditional with Pixel Color?

    I want that get pixel of the actual screen; in a started timer.

    Don't detect a pixel with ..GetPixel(1014, 615) and is the same color.

  13. #13

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: Conditional with Pixel Color?

    I only need to do that in coord (1000, 500) if is #FF09532 do something, and else, another thing.

    Code:
    If coord (1000, 500) = #FF09532 Then
          Textbox1.text = "Hello"
    Else
          Textbox1.text = "Bye"
    End If
    For example.
    Last edited by pguti19; Apr 26th, 2013 at 10:58 AM.

  14. #14
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,386

    Re: Conditional with Pixel Color?

    Quote Originally Posted by pguti19 View Post
    I only need to do that in coord (1000, 500) if is #FF09532 do something, and else, another thing.
    Of the form or the whole screen?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  15. #15

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: Conditional with Pixel Color?

    Is one windows of Google Chrome where i want scan.

    The scan is enabled by other conditional.

    Code:
    If textbox2.text = "0" Then
      If coord (1000, 500) = #FF09532 Then
          Timer3.start()
      Else
          Timer2.stop()
          Timer1.stop()
      End If
    End If
    One example.

  16. #16

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: Conditional with Pixel Color?

    Okey, now i can make this Conditional, but i need how to equate this:

    Code:
            Dim myBmp As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
    
            If Label1.BackColor = mybmp.GetPixel(TextBox1.Text, TextBox2.Text) Then
                label2.text = "YEAH"
            Else
                label2.text = "D:"
            End If
    Because If i put the same color, Label2.text is "D:" and have to write "YEAH"...

  17. #17

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Thumbs up Re: Conditional with Pixel Color?

    Sorry for triple post.

    SOLVED:

    Code:
        Public Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As IntPtr) As Integer
        Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer) As Integer
    ____________________________________________________________________________________________________________________
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Dim myBmp As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
            Dim g As Graphics = Graphics.FromImage(myBmp)
            g.CopyFromScreen(Point.Empty, Point.Empty, myBmp.Size)
            g.Dispose()
            Label2.BackColor = myBmp.GetPixel(TextBox1.Text, TextBox2.Text)
            myBmp.Dispose()
    
        End Sub
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Timer2.Start()
        End Sub
    
        Private Sub Timer2_Tick(sender As System.Object, e As System.EventArgs) Handles Timer2.Tick
            Dim myBmp As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
    
            If Label2.BackColor = Label1.BackColor Then
                Label2.Text = "YEAH"
                Timer2.Stop()
            Else
                Label2.Text = "D:"
                Timer2.Stop()
            End If
    
        End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width