Results 1 to 9 of 9

Thread: Color Snap

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Location
    Malaysia
    Posts
    3

    Color Snap

    I wish to build to program which is able snap a point in windows or i should say get a coordinate of that point based on the given color. Do anyone have idea how to do it? Thanks for help.

  2. #2
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Do you meen search through a graphic (picbox etc or screen) looking for a certain colour?
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Location
    Malaysia
    Posts
    3
    yes. I think WinAPI can do it but i dont know which command to use. Please give me an example code if you can. Thanks again for help.

  4. #4
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    use the GetPixel API (or you can use the point method of pictureboxes/forms).
    Involved in: Sentience

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    That won't help much - he needs to know how.

    Ok, add the declaration from the API viewer as you would any other API call. Then, use the function like below. Remember you'll also have to get the PointAPI declaration from the Types field of the API viewer:
    VB Code:
    1. Function SearchForColour(ByRef mPic As PictureBox, ByRef Ret() As PointAPI, ByRef Colour As Long)
    2. Dim X As Long
    3. Dim Y As Long
    4. Dim Count As Long
    5.  
    6. mPic.ScaleMode = 3 'vbPixels
    7. For Y = 0 To mPic.ScaleHeight
    8.    For X = 0 To mPic.ScaleWidth
    9.       If GetPixel(X, Y, mPic.hDC) = Colour Then
    10.       Count = Count + 1
    11.       Redim Preserve Ret(0 To Count - 1) As PointAPI
    12.       With Ret(Count - 1)
    13.          .X = X
    14.          .Y = Y
    15.       End With
    16.    Next X
    17. Next Y
    The code hasn't been tested, but should work. Just go through the Ret() array, just Ret(0) if you aren't expecting more than 1 match. You might use it like this:
    VB Code:
    1. Dim myArr() As PointAPI
    2. Dim I As Long
    3.  
    4. On Error Goto NoBlack
    5.  
    6. SearchForColour Picture1, myArr, RGB(0, 0, 0)
    7.  
    8. For I = LBound(myArr) To UBound(myArr)
    9.    Msgbox "Pure Black found at X: " & myArr(I).X & " Y: " & myArr(I).Y & ".", , "Black Found!"
    10. Next I
    11.  
    12. NoBlack:
    13. Msgbox "No Pure Black in Picturebox!", , "No Black!"
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  6. #6
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Don't forget the Extra type used there!

    VB Code:
    1. Public Type POINTAPI
    2.         x As Long
    3.         y As Long
    4. End Type
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Location
    Malaysia
    Posts
    3
    I think those example is sufficient for me to build the program. I appreciate the advises from you guys and thanks a lot.

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Ok, add the declaration from the API viewer as you would any other API call. Then, use the function like below. Remember you'll also have to get the PointAPI declaration from the Types field of the API viewer:
    SLH -
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  9. #9
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051


    Ah well, may have saved him some time.... or not
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


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