简体   繁体   English

为什么System.Drawing.Color不是枚举

[英]Why is System.Drawing.Color not an enum

为什么System.Drawing.Color是一个structSystem.ConsoleColor是一个枚举

Because the console only supports a small set of colours, whereas System.Drawing models all possible 24-bit colours (32-bit with alpha). 因为控制台仅支持一System.Drawing颜色,而System.Drawing模拟所有可能的24位颜色(带有alpha的32位颜色)。 That's over 4 billion possible colours, which would be a big enum! 这超过40亿种可能的颜色,这将是一个很大的枚举!

Here are the console colours: 以下是控制台颜色:

在此输入图像描述

There are 16 foreground, plus 16 background colours. 有16个前景,加上16个背景颜色。

Note that in System.Drawing some colours are given names , but they're not an enum -- they're static fields, such as Color.Red and Color.Aquamarine . 请注意,在System.Drawing 某些颜色被赋予名称 ,但它们不是枚举 - 它们是静态字段,例如Color.RedColor.Aquamarine

The same is true of System.Windows.Media.Color (as used in WPF). System.Windows.Media.Color (在WPF中使用)也是如此。

Because there are 16 well known colors for console, but 16777216 colors (plus 256 alpha levels for each) that can be used in general. 因为控制台有16种众所周知的颜色,但通常可以使用16777216种颜色(每种颜色加256个alpha级别)。 Would you like to name all 4 billion of them and write code that then converts these enums back into actual RGBA values? 您想要命名所有40亿个并编写代码然后将这些枚举转换回实际的RGBA值吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM