我想實現計算RGB和CMYK,反之亦然之間的轉換解決方案。以下是我迄今爲止:RGB到CMYK和背部算法
public static int[] rgbToCmyk(int red, int green, int blue)
{
int black = Math.min(Math.min(255 - red, 255 - green), 255 - blue);
if (black!=255) {
int cyan = (255-red-black)/(255-black);
int magenta = (255-green-black)/(255-black);
int yellow = (255-blue-black)/(255-black);
return new int[] {cyan,magenta,yellow,black};
} else {
int cyan = 255 - red;
int magenta = 255 - green;
int yellow = 255 - blue;
return new int[] {cyan,magenta,yellow,black};
}
}
public static int[] cmykToRgb(int cyan, int magenta, int yellow, int black)
{
if (black!=255) {
int R = ((255-cyan) * (255-black))/255;
int G = ((255-magenta) * (255-black))/255;
int B = ((255-yellow) * (255-black))/255;
return new int[] {R,G,B};
} else {
int R = 255 - cyan;
int G = 255 - magenta;
int B = 255 - yellow;
return new int[] {R,G,B};
}
}
大家總是想要快速的回答,其無用的指定 – Eric 2011-02-01 01:59:21
這個解決方案是如何爲你工作的?我看到你試圖在沒有ICC_Colorspace的情況下繼續下去,你能保持它嗎? – TacB0sS 2014-05-30 20:39:46