如何“自然地"混合颜色用 C#?

编程入门 行业动态 更新时间:2024-10-26 11:19:12
本文介绍了如何“自然地"混合颜色用 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#?

本文发布于:2023-05-25 10:52:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/226580.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自然地   颜色   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!