How to convert RGB to HSL in C?
问题 How do I convert RGB to HSL in C/C++? (Note: This is a (short) self-answer -- I posted it here so people can find it quickly with a search.) 回答1: Translating the code from here, you get: // Assuming sizeof(unsigned int) == 4 * sizeof(unsigned char) unsigned int RgbToHsl(unsigned int rgb) // Alpha value is simply passed through { #ifdef __cplusplus using std::max; using std::min; #endif double r = (rgb >> (0 * CHAR_BIT)) & UCHAR_MAX, g = (rgb >> (1 * CHAR_BIT)) & UCHAR_MAX, b = (rgb >> (2 *