Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么将RGB转换为CMYK不能显示正确的结果_C#_Colors - Fatal编程技术网

C# 为什么将RGB转换为CMYK不能显示正确的结果

C# 为什么将RGB转换为CMYK不能显示正确的结果,c#,colors,C#,Colors,我将此网站用作参考: 我的代码: 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 =

我将此网站用作参考:

我的代码:

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);

如果您只是替换
k=minCMY*100
使用
k=minCMY
它会起作用。实际上,rapidtables.com发布了他们的算法,您的代码看起来与他们的算法相似,但并不完全相同,因此,我不明白是什么阻止了你简单地修改代码,使其更接近于他们的工作方式,从而使其正常工作。
*100
似乎是所有四个等式的罪魁祸首。我的意思是,我不知道你为什么要做任何乘以100的乘法。rapidtables.com上没有出现类似的内容。^对。就在我打字的时候。