我使用此网站作为参考:http://www.rapidtables.com/convert/color/rgb-to-cmyk.htm
我的代码:
public void Convert2CMYK()
{
float c, m, y, k;
if (inRed == 0 && inGreen == 0 && inBlue == 0)
{
tbCyan.Text = "0";
tbMagenta.Text = "0";
tbYellow.Text = "0";
tbBlack.Text = "1";
}
c = 1 - (inRed / 255f);
m = 1 - (inGreen / 255f);
y = 1 - (inBlue / 255f);
var minCMY = Math.Min(c, Math.Min(m, y));
c = (c - minCMY) / (1 - minCMY) * 100;
m = (m - minCMY) / (1 - minCMY) * 100;
y = (y - minCMY) / (1 - minCMY) * 100;
k = minCMY * 100;
tbCyan.Text = c.ToString();
tbMagenta.Text = m.ToString();
tbYellow.Text = y.ToString();
tbBlack.Text = k.ToString();
}
在现场,R = 25,G = 25,B = 25导致C = 0,M = 0,Y = 0,K = 0.902
在app(我的代码)中,R = 25,G = 25,B = 25导致C = 0,M = 0,Y = 0,K = 90.19608
我需要修改哪些内容才能确保结果准确无误。
答案 0 :(得分:2)
感谢大家的帮助。以下是完成这一操作的最终方程式:
c = Math.Round((c - minCMY) / (1 - minCMY), 3);
m = Math.Round((m - minCMY) / (1 - minCMY), 3);
y = Math.Round((y - minCMY) / (1 - minCMY), 3);
k = Math.Round(minCMY, 3);