Tuesday, December 16, 2008

[vb6] Extract red, green or blue component from color value

The individual color components of an RGB value held in a long can be extracted with some bit manipulation to give values in the range 0 to 255:
    Private Function Red&(ByVal Color&)
Red = Color And (Not &HFFFFFF00)
End Function
Private Function Green&(ByVal Color&)
Green = (Color And (Not &HFFFF00FF)) \ &H100&
End Function
Private Function Blue&(ByVal Color&)
Blue = (Color And (Not &HFF00FFFF)) \ &HFFFF&
End Function

No comments:

Post a Comment