Results 1 to 9 of 9

Thread: GetPixel API

  1. #1

    Thread Starter
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183

    Question

    Hello,
    I notice that when I use the GetPixel API the result isn’t in the RGB format. I’m unfamiliar to whichever method it is using so would someone please notify me of any method of converting the result from the GetPixel API into RGB format? Thanks

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    This one has always confused me, I never quite worked out exactly what it was doing, it always seemed to me that some API Functions came back with RGB results in the correct form and some come back with the components mixed up (the red bit where the blue should be etc.

    I think it's a bug rather than anything else

    Try putting the results of pixels coloured gompletley red, blue or green into an RGBQUAD, se if you can work out which colour componentss are going where.


  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    The GetPixel function returns a BGR encoded colour, in the format: 0xBBGGRR. So, use this to extract the items:
    Code:
    Private Type ColourRGB
        lRed As Integer
        lGreen As Integer
        lBlue As Integer
    End Type
    Private Sub Form_Load()
        Dim z As ColourRGB
        z = ExtractColour(RGB(&HAA, &HBB, &HCC))
        Debug.Print Hex(z.lRed)
        Debug.Print Hex(z.lGreen)
        Debug.Print Hex(z.lBlue)
    End Sub
    Private Function ExtractColour(lColour As Long) As ColourRGB
        Dim tempC As ColourRGB
        tempC.lBlue = (lColour \ &H10000) And &HFF
        tempC.lGreen = (lColour \ &H100) And &HFF
        tempC.lRed = lColour And &HFF
        ExtractColour = tempC
    End Function
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Guest
    Try this:
    Code:
    lColor = GetPixel(Picture1.hdc, 32, 32)
        
    'Get Red, Green and Blue
    lRed = lColor Mod &H100
    lGreen = Int(lColor / &H100) Mod &H100
    lBlue = Int(lColor / &H10000) Mod &H100

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Just noticed...it's buggered the numbers. The &h10000 and such should be all together, with no spaces.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6

    Thread Starter
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183

    Thumbs up

    Thanks guys I'll give all the suggestions a try.

  7. #7

    Thread Starter
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183

    Question

    By the way, what does
    Code:
    Mod
    do? It's a command that I've never came across.

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    The Modulus operator divides two numbers and returns the remainder:
    Code:
    res = 20 Mod 6
    res is now 2 (since 20 / 6 = 18 r 2)
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9

    Thread Starter
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183

    Smile

    Oh yes, it the equivalent to % in C++. Thanks Parksie.

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