devxlogo

Extract Red,Green,Blue components of a color

Extract Red,Green,Blue components of a color

If you have a 32-bit color value in RGB format, you can extract its Red, Green and Blue components using the following routines:

Function GetRed(ByVal lColor As Long) As Long    GetRed = lColor Mod 256End FunctionFunction GetGreen(ByVal lColor As Long) As Long    GetGreen = (lColor  &H100) Mod 256End FunctionFunction GetBlue(ByVal lColor As Long) As Long    GetBlue = (lColor  &H10000) Mod 256End Function

Remember that you can combine the red, green and blue components into a RGB color using the built-in RGB function

rgbColor = RGB(redColor, greenColor, blueColor)

devx-admin

Share the Post: