如何混合颜色“自然”用C#? [英] How to mix colors "naturally" with C#?

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

问题描述

我必须以自然的方式混合一些颜色。这意味着

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

blue + yellow = green 
blue + red = purple

等等。我得到的颜色作为RGB值。当我尝试混合它们时,我得到了正确的RGB结果,如

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

但不是正确的自然湿漆任何好的主意如何以自然的方式混合RGB?

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

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

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: p>

@Jay Bazuzi:


请发布一个代码示例,显示
您要做什么。

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

当然 - 这是我混合两个RGB颜色的功能。

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

我在这个线程中读到的内容非常有前途 - C1和C2到L a b *,混合 - 将它们转换回RGB并返回该颜色。

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.

推荐答案

天然湿漆有点含糊;

如果你想要像Photoshop中的结果(作为Jon B检查),那么CMYK的混合将不会工作,因为你还在添加颜色。需要使用L * a * b *空格。用于将RGB转换为/来自Lab的说明在这里

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.

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

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