将用CMYK编码的颜色转换为十六进制等效的公式是什么?
答案 0 :(得分:4)
我有坏消息:没有简单的公式。青色,品红色和黄色是复杂的墨水颜色,RGB的转换取决于colour profiles。更糟糕的是,CMYK颜色空间小于RGB颜色空间。关于色彩理论的一些指示:
答案 1 :(得分:1)
可以使用javascript完成
//converts cmyk to hex
function cmykToHex(c,m,y,k) {
var hex,
rgb;
//convert cmyk to rgb first
rgb = cmykToRgb(c,m,y,k);
//then convert rgb to hex
hex = rgbToHex(rgb.r, rgb.g, rgb.b);
//return hex color format
return hex;
}
//converts cmyk color to rgb
function cmykToRgb(c, m, y, k) {
var rgb_r,
rgb_g,
rgb_b,
cyan = 100 *Number(c),
magenta = 100 * Number(m),
yellow = 100 * Number(y),
black = 100 * Number(m);
0 < cyan ? cyan /= 100 : 0 < magenta ? magenta /= 100 : 0 < yellow ? yellow /= 100 : 0 < black && (black /= 100);
rgb_r = 1 - Math.min(1, cyan * (1 - black) + black);
rgb_g = 1 - Math.min(1, magenta * (1 - black) + black);
rgb_b = 1 - Math.min(1, yellow * (1 - black) + black);
rgb_r = Math.round(255 * rgb_r);
rgb_g = Math.round(255 * rgb_g);
rgb_b = Math.round(255 * rgb_b);
return {r: rgb_r, g: rgb_g, b: rgb_b};
}
//converts rgb to hex
function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
function componentToHex(c) {
var hex = c.toString(16);
return hex.length === 1 ? "0" + hex : hex;
}
}