有朋友可能会问,CMYK是浮点数,要保存怎么办?可以乘0xFF(255)。
void RGB2CMYK(int red, int green, int blue, double& c, double& m, double& y, double& k) { c = (0xFF - red ) / 255.0; m = (0xFF - green) / 255.0; y = (0xFF - blue ) / 255.0; k = Math.min(c, Math.min(m, y)); if (k == 1.0) { c = m = y = 0; } else { c = (c - k) / (1 - k); m = (m - k) / (1 - k); y = (y - k) / (1 - k); } } void CMYK2RGB(double c, double m, double y, double k, int& r, int& g, int& b) { r = (int)((1.0 - c) * (1.0 - k) * 0xFF); g = (int)((1.0 - m) * (1.0 - k) * 0xFF); b = (int)((1.0 - y) * (1.0 - k) * 0xFF); }