我目前正在尝试为控制台和终端仿真器创建某种图形界面框架,类似于 lanterna ,但采用更具声明性的方法,但是我偶然发现了让我头疼好几天的东西:颜色。
我期待的是一种独立于底层实现和方案(ANSI、Indexed、)来表示颜色和调色板的方法24 位 用于 VGA、xterm、Windows..)。我最初的想法是创建一个简单的结构来表示 RGB 颜色空间中的颜色:
public struct Color {
public byte R, G, B;
}
... 并声明一组预定义的颜色,例如 public static readonly Color Black = new Color(0, 0, 0);
但是这可能行不通,因为例如xterm 上的red 与Windows 控制台 中的red 不同。然后我考虑使用 enum
,但在这里我无法定义颜色的确切值。
实现这一目标的可能方法是什么?是否有其他颜色空间可能比 RGB 更适合表示颜色?
最佳答案
Also, it would be nice if they could be combine e.g: Color Yellow = Color.Red | Color.Green. Does this make sense somehow?
如果 Color 只是一个整数,那么 Color.Yellow == Color.Red | Color.Green 无需任何额外代码即可工作(相当于 0xFFFF00 == 0xFF0000 | 0x00FF00)。如果您希望颜色具有单独的 R、G 和 B 属性,那么您可以进行一些奇特的运算符重载并让它仍然有效。
What I'm looking forward to is a way to represent colors as well as color palettes independently of the underlying implementation and scheme (ANSI, Indexed, 24-bit for VGA, xterm, Windows..). My initial idea was to create a simple struct that represents a color in the RGB color space:
...
Are there other color spaces that might be more suitable to represent colors than RGB?
我是这个的粉丝:
http://en.wikipedia.org/wiki/Lab_color_space
这解释了原因:
http://mycarta.wordpress.com/2012/05/29/the-rainbow-is-dead-long-live-the-rainbow-series-outline/
关于c# - 代表颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26735316/