<< Back to Category List
Converting Long Color Values to RGB - page 1 |
pages:
prev | 1 | next
Converting Long Color Values to RGB
By Brian Clark
Please feel free to send comments to troll1184@cs.com
Step 1. Creating a Type
Ok the first thing you will need to do is add the following declare statement to a new MODULE.
Note: This is what will store our values in after the function has been called
Public Type RGB
Red As Integer
Green As Integer
Blue As Integer
End Type
Step 2. Creating the Core Function
This is the real code that does the work
Public Function lng2RGB(lngColor As Long) As RGB
Dim tmpRGB As RGB
'lngColor is a Long containing the color
'convert it to RGB
tmpRGB.Red = lngColor Mod 256
lngColor = (lngColor - tmpRGB.Red) / 256
tmpRGB.Green = lngColor Mod 256
lngColor = (lngColor - tmpRGB.Green) / 256
tmpRGB.Blue = lngColor
lng2RGB = tmpRGB
End Function
Step 3. Calling the lng2RGB Function
To use the function call it like this:
Public Sub cmdTest_Click()
Dim RGB as RGB
Dim lngPixelVal as Long
?The long value we use will come from a GetPixel API call, and be something like
?65504
lngPixelVal = GetPixel(form1.hdc, 0, 0)
RGB = lng2RGB(lngPixelVal)
End Sub
Ok, now our RGB type will be filled with the values for Red, Green, and Blue(ie 255,255,124)
Step 4. Ending notes
Ok I know your probably saying something like "This is the shortest tutorial I?ve ever seen", but I know that a lot of people have has problems getting their RGB?s from Api calls.
Thanks for spending the time to read this tutorial. Please send me comments
Written By:
Brian Clark
pages:
prev | 1 | next |