the black hole 
it all ends here. 
bhC login
name:
pass:
 
home
 
 the black hole's front page. all the latest vb rpg development and vbgaming news, as well as this week's feature rpg project!
articles
 
rpg theory (7)
directx in vb (3)
vb rpg programming (4)
miscellaneous (4)
files
 
rpg / tile engine source (23)
full vb games w/ source (5)
'helper' libraries and utilities (13)
effect samples (5)
miscellaneous (10)
rpg projects
 
 vb rpg projects under development by members of the bhC. show them your support, and check out their games!
message board
 
 a forum to interact with your fellow vb rpg programmers. you do *not* have to be a bhC member to post!
links
 
vb rpg programming (5)
vb gaming (14)
general game programming (6)
vb sites (6)
miscellaneous (2)
general rpg programming (2)
contact
 
 you want to contact the guy behind the black hole? here's where to do it!


 
 


<< 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