Results 1 to 3 of 3

Thread: Pixel Color Detection

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2000
    Posts
    55

    Pixel Color Detection

    How do i check what color the pixel is in a certain size box? I want to make a box that is about 100x100 pixels in the center of the screen, that checks for certain colors then if it detects them it executes a function.
    Everyone is a begginer at some time, but we all get our fame.

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    VB Code:
    1. Declare Function GetPixel.... () ... 'whatever goes here!
    2. Type RECT
    3.     Left as Long
    4.     Right as Long
    5.     Top as Long
    6.     Bottom as Long
    7. End Type
    8.  
    9. Function Check(R as RECT) 'R is the box that you have, for a 100x100 set this to .bottom = 100, .right = 100
    10. Dim A
    11. Dim H
    12.     For A = R.Top to R.Bottom
    13.         For H = R.Left to R.Right
    14.             If GetPixel(mypicturebox.hDC, A, H) = RGB(0,0,0) Then 'checks for black
    15.                 Myfunction()
    16.                 Exit For
    17.                 Exit For
    18.                 Exit Function
    19.             End If
    20.         Next H
    21.     Next A
    22. End Function
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    Addicted Member Dim A's Avatar
    Join Date
    Jul 2000
    Posts
    201
    Here's the API declaration...

    Code:
    Declare Function GetPixel Lib "gdi32" Alias "GetPixel" _
          (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    alternatively you can use the picture point method...

    Code:
    if picture1.point(x,y)=vbblack then
    - Dim A

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