Results 1 to 8 of 8

Thread: Get RGB Bits from LONG

  1. #1

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I'm not sure how to get the red, green, and blue bits from the long data type that is returned from the getpixel routine. Could anybody show me how to do this?

    A=getpixel(5,5,me.hdc)

    What is a's red value (0-255)?
    What is a's green value (0-255)?
    What is a's blue value (0-255)?
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Enjoy!

    Code:
    Private Sub Form_Load()
     Dim lColor As Long
    
     lColor = RGB(225, 75, 180)
    
     Debug.Print GetR(lColor)
     Debug.Print GetG(lColor)
     Debug.Print GetB(lColor)
    
    End Sub
    
    Private Function GetR(ByVal pCol As Long) As Byte
       
       GetR = pCol Mod 256
    
    End Function
    
    Private Function GetG(ByVal pCol As Long) As Byte
        
       pCol = pCol \ 256
       GetG = pCol Mod 256
        
    End Function
    
    Private Function GetB(ByVal pCol As Long) As Byte
    
        pCol = (pCol \ 256) \ 256
        GetB = pCol Mod 256
    
    End Function
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Thanks Youngbuck; I thought it could only be done with hex. (I forgot the code, its in a microsoft MSChart MSDN thing or something)

    Thanks!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  4. #4
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987

    Hex GetR, GetG, GetB

    Code:
    Private Sub Form_Load()
     Dim lColor As Long
    
     lColor = RGB(255, 255, 255)
    
     Debug.Print GetR(lColor)
     Debug.Print GetG(lColor)
     Debug.Print GetB(lColor)
    
    End Sub
    
    Private Function GetR(ByVal pCol As Long) As Byte
       
       GetR = pCol Mod &H100
    
    End Function
    
    Private Function GetG(ByVal pCol As Long) As Byte
        
       pCol = pCol \ &H100
       GetG = pCol Mod &H100
        
    End Function
    
    Private Function GetB(ByVal pCol As Long) As Byte
    
        pCol = (pCol \ &H100) \ &H100
        GetB = pCol Mod &H100
    
    End Function
    Better?
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Sas! Check out how you could do this without any mathematical operators:
    http://forums.vb-world.net/showthrea...rgb#post219447
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Shuts up, sits cross legged in the corner and listens to the Guru!
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  7. #7

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    yo kedaman, get a better avatar!
    (not that i dont like your drawing)

    goto www.yahoo.com
    search for 'chrono trigger dance party'
    go to the page and download your favourite character!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    damn, why don't you like my cool avatari Sas?!

    Ok, thanks for the suggestion
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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