LongToRGB

By | 2002-06-01

Converts Long values (used by getpixel and other low level color functions) into RGB values that you can use. Useful if you want to manually remap an image or make some kind of color effect.

Original Author: Reboot

Inputs

Long color value (from getpixel or rgb(), etc)

Returns

Three paramaters, r g and b, red green blue

Code

Private Type zRGB
R As Long
G As Long
B As Long
End Type
Private Sub Form_Load()
'this is just an example
'if you don't tweak the code, you will have to
'dim a variable as "zRGB" that stores the returns
Dim cRGB As zRGB
cRGB = LongToRGB(RGB(255, 250, 255))
MsgBox cRGB.R & ", " & cRGB.G & ", " & cRGB.B
End
End Sub
Private Function LongToRGB(ColorValue As Long) As zRGB
Dim rCol As Long, gCol As Long, bCol As Long
rCol = ColorValue And &H10000FF 'this uses binary comparason
gCol = (ColorValue And &H100FF00) / (2 ^ 8)
bCol = (ColorValue And &H1FF0000) / (2 ^ 16)
LongToRGB.R = rCol
LongToRGB.G = gCol
LongToRGB.B = bCol
End Function

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.