为什么将 RGB 转换为 CMYK 没有显示正确的结果
Why is converting RGB to CMYK not showing the correct result
我正在使用这个网站作为参考: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
在应用程序(我的代码)中,R=25、G=25、B=25 导致 C=0、M=0、Y=0、K=90.19608
我必须修改什么才能确保我的结果准确。
感谢大家的帮助。这是成功的最终方程式:
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);
我正在使用这个网站作为参考: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
在应用程序(我的代码)中,R=25、G=25、B=25 导致 C=0、M=0、Y=0、K=90.19608
我必须修改什么才能确保我的结果准确。
感谢大家的帮助。这是成功的最终方程式:
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);