Jump to content
  • Advertisement
Sign in to follow this  
gaerg

Integer to RGB components

This topic is 3283 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!