VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



LongToRGB

by Reboot (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (5 Votes)

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.

Inputs
Long color value (from getpixel or rgb(), etc)
Code Returns
Three paramaters, r g and b, red green blue

Rate LongToRGB

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

Download this snippet    Add to My Saved Code

LongToRGB Comments

No comments have been posted about LongToRGB. Why not be the first to post a comment about LongToRGB.

Post your comment

Subject:
Message:
0/1000 characters