Jump to content
  • Advertisement
Sign in to follow this  
gaerg

Integer to RGB components

This topic is 3195 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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!