• Advertisement
Sign in to follow this  

Integer to RGB components

This topic is 2979 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I convert an integer value to r, g and b components? E.g. GetRed(16777215); Would return 255. And similar functions for green and blue.

Share this post


Link to post
Share on other sites
Advertisement
This is hiow I convert between long and rgb



CRgb( unsigned long Color )
{
this->rgbAlpha = static_cast<unsigned char>( (Color >> 24 ) & 0xFF );
this->rgbRed = static_cast<unsigned char>( (Color >> 16 ) & 0xFF );
this->rgbGreen = static_cast<unsigned char>( (Color >> 8 ) & 0xFF );
this->rgbBlue = static_cast<unsigned char>( Color & 0xFF );
}




Now I look at it, you can actully leave out the first bitand with 0xFF

Share this post


Link to post
Share on other sites
Thanks it works great! I googled for that like an hour without any results.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement