如何搭配颜色和QUOT;自然"用C#? [英] How to mix colors "naturally" with C#?

查看:260
本文介绍了如何搭配颜色和QUOT;自然"用C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要搭配一些色彩以自然的方式。这意味着

 蓝+黄=绿
蓝+红=紫
 

等。我得到了颜色的RGB值。当我尝试将它们混合我得到了正确的RGB - 结果像

 绿+红=黄色
黄+蓝=白
 

但不正确的天然湿漆 - 结果。任何好的想法如何搭配RGB以自然的方式?

这是在code我有添加颜色:

众彩colorMixer(颜色C1,C2颜色) {     INT _r = Math.Min((c1.R + c2.R),255);     INT _G = Math.Min((c1.G + c2.G),255);     INT _b = Math.Min((c1.B + c2.B),255);     返回新颜色(Convert.ToByte(_r)                      Convert.ToByte(_G)                      Convert.ToByte(_b)); }

这将是巨大的,如果有人知道 Microsoft.Xna.Framework.Graphics 命名空间中的一个解决方案,但一个通用的解决方案也将有助于:)


@Jay Bazuzi:

  

请张贴code示例,演示   你想做什么。

当然 - 这是我的函数混合两种RGB-颜色。

 众彩colorMixer(颜色C1,C2颜色)
{

    INT _r = Math.Min((c1.R + c2.R),255);
    INT _G = Math.Min((c1.G + c2.G),255);
    INT _b = Math.Min((c1.B + c2.B),255);

    返回新颜色(Convert.ToByte(_r)
                     Convert.ToByte(_G)
                     Convert.ToByte(_b));
}
 

我已经阅读迄今在这个线程是非常有前途的 - 我将C1和C2转换为L的的B *,将它们混合 - 它转换回RGB,回到那个颜色

解决方案

自然油漆未干有点暧昧; CMYK的混合的建议是行不通的,因为你还添加颜色。

如果你想要像在Photoshop结果(乔恩乙选中),你需要使用的L * a * b *的空间。公式转换RGB /从实验室和描述的is这里

Lab空间被特别设计成使得线性变化对应于什么人眼感知为一定量的颜色变化。这是重要的,因为例如我们是绿色的比其他颜色更敏感,因为我们认为不同的变化取决于双方的色度和亮度等。

试图目前正在建议不仅会导致颜色你不想要的,但也不会再present颜色的恒看的变化,特别是如果你使用的东西,其中的任何其他方法不断变化的问题​​就像一个梯度。

I have to mix some colors in a natural way. This means

blue + yellow = green 
blue + red = purple

and so on. I got the colors as RGB-Values. When I try to mix them I got the right "RGB"-results like

green + red = yellow
yellow + blue = white

but not the right "natural-wet-paint"-results. Any good idea how to mix RGB in a natural way?

This is the code I have for adding the colors:

public Color colorMixer(Color c1, Color c2)
{

    int _r = Math.Min((c1.R + c2.R),255);
    int _g = Math.Min((c1.G + c2.G),255);
    int _b = Math.Min((c1.B + c2.B),255);

    return new Color(Convert.ToByte(_r),
                     Convert.ToByte(_g),
                     Convert.ToByte(_b));
}

It would be great if someone knew a solution within the Microsoft.Xna.Framework.Graphics namespace but a generic solution would also help :)


@Jay Bazuzi:

Please post a code sample that shows what you're trying to do.

Sure - this is my function for mixing the two RGB-Colors.

public Color colorMixer(Color c1, Color c2)
{

    int _r = Math.Min((c1.R + c2.R),255);
    int _g = Math.Min((c1.G + c2.G),255);
    int _b = Math.Min((c1.B + c2.B),255);

    return new Color(Convert.ToByte(_r),
                     Convert.ToByte(_g),
                     Convert.ToByte(_b));
}

What I have read so far in this thread is very promising - I will convert C1 and C2 to Lab* , mix them - convert it back to RGB and return that color.

解决方案

"Natural wet paint" is a little ambiguous; the mixing of CMYK as suggested won't work because you're still adding colors.

If you want results like in Photoshop (as Jon B checked) you need to use L*a*b* space. Formulas for converting RGB to/from Lab and a description is here.

Lab space was specifically designed so that linear changes correspond to what the human eye perceives as a certain amount of color change. This is important because e.g. we are more sensitive to green than other colors, because we perceive changes differently depending both on hue and lightness, etc..

Trying any other methods currently being suggested will not only result in colors you don't want, but also won't represent a "constant-looking" change in color, especially if you use this for something where constant-change matters like a gradient.

这篇关于如何搭配颜色和QUOT;自然"用C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆