Results 1 to 5 of 5

Thread: GetPixel API giving me a headache

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 1999
    Location
    Kempton Park, Guateng, South Africa
    Posts
    24
    The GetPixel api returns a RGB value of a certain pixel at a certain point but it gives it in a single value (i.e. it doesn't give you the individual RGB values as in R,G,B) Is there anyway of discovering the individual RGB values from the single value passed back by this API? Is there maybe any other way of getting the R,G,B value of a pixel?

    This is really making me stand on my head so if somone can help me, I would be very appreciative.
    "He who laughs at a question is not worth being asked"

    RavenCrow

  2. #2
    Junior Member
    Join Date
    Apr 2000
    Posts
    24

    Hmmm....

    I don't remember all the GetPixel stuff but I think you could try and make a sub that reads all three RGB values and returns them or something. Once again, I don't know all the specifics of GetPixel so I'm not sure.

  3. #3
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715

    Functions

    Hi,

    These functions work fine for me.

    OET

    Private Function GetRed(colorVal As Long) As Integer
    On Error Resume Next
    GetRed = colorVal Mod 256
    End Function

    Private Function GetGreen(colorVal As Long) As Integer
    On Error Resume Next
    GetGreen = ((colorVal And &HFF00FF00) / 256&)
    End Function

    Private Function GetBlue(colorVal As Long) As Integer
    On Error Resume Next
    GetBlue = (colorVal And &HFF0000) / 65535 '(256& * 256&)
    End Function

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Code:
    Option Explicit
    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    Private Const CLR_INVALID = &HFFFF
    
    Private Sub Command1_Click()
    Dim MyColor As Long
    Dim r As Byte
    Dim g As Byte
    Dim b As Byte
        MyColor = GetPixel(Me.hdc, 10&, 10&)
        If MyColor <> CLR_INVALID Then
            r = MyColor And &HFF
            g = (MyColor And &HFF00FF00) / &H100
            b = (MyColor And &HFF0000) / &H10000
            MsgBox "Red : " & r & vbCrLf & "Green : " & g & vbCrLf & "Blue : " & b
        End If
    End Sub

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 1999
    Location
    Kempton Park, Guateng, South Africa
    Posts
    24

    Thank you!!

    Thank you soooo much for the Red Green & blue functions!!!

    It is very very much appretiated!!


    "He who laughs at a question is not worth being asked"

    RavenCrow

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