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

查看:29
本文介绍了如何“自然地"混合颜色用 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:

@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 转换为 Lab*,将它们混合 - 将其转换回 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.

推荐答案

天然湿漆"有点含糊;建议的 CMYK 混合不起作用,因为您仍在添加颜色.

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

如果您想要像 Photoshop 中的结果(如 Jon B 所检查),您需要使用 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天全站免登陆