Click to See Complete Forum and Search --> : Get RGB Bits from LONG
Sastraxi
Feb 2nd, 2001, 09:26 PM
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)?
YoungBuck
Feb 2nd, 2001, 09:42 PM
Enjoy!
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
Sastraxi
Feb 2nd, 2001, 09:44 PM
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!
YoungBuck
Feb 2nd, 2001, 09:49 PM
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? ;)
kedaman
Feb 3rd, 2001, 06:05 AM
Sas! Check out how you could do this without any mathematical operators:
http://forums.vb-world.net/showthread.php?s=&postid=219447&highlight=copymemory+rgb#post219447
YoungBuck
Feb 3rd, 2001, 06:44 AM
Shuts up, sits cross legged in the corner and listens to the Guru! :o :o :o :o ;)
Sastraxi
Feb 3rd, 2001, 04:53 PM
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!
kedaman
Feb 3rd, 2001, 05:27 PM
Ok, thanks for the suggestion
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.