简体   繁体   中英

Convert RGB to Hex C++?

I am looking for a simple C++ function that takes three integers as r, g, and b and returns the corresponding hex color code as an integer. Thanks in advance!

int hexcolor(int r, int g, int b)
{
    return (r<<16) | (g<<8) | b;
}

Of course you'll need some output formatting to show it as hex.

unsigned long rgb = (r<<16)|(g<<8)|b; 

given that r,g,b are unsigned 8bit chars.
(That´s really easy, and Google would´ve helped.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM