如何生成这个特定的数字序列?
显然.net 中没有可用的预定义列表。
我想使用一些标准颜色,例如红、绿、蓝、黄……即由 00 和 FF 分量组成的典型颜色,后面是带有附加 7F 分量的颜色,……
有吗一种检索这些“标准”颜色的方法,还是我必须自己编写 IEnumerable
编辑:这是 RGB 值的可能输出。
请注意集合的顺序很重要,因为 00/FF 枚举必须在添加 80 之前完成,并且 00/80/FF 枚举必须在添加 40/B0 之前完成,所以在。 集合中的顺序并不重要(即 00 FF 00 可能出现在 00 00 FF 之前)。
00 00 00 // start out with 00 and FF components
00 00 FF
00 FF 00
FF 00 00
FF FF 00
FF 00 FF
00 FF FF
FF FF FF
00 00 80 // ok, now add 80
00 80 00
...
80 80 80
FF 00 80
FF 80 00
FF 80 80
80 FF 00
80 FF 80
FF FF 80
...
// now add 40 and B0
Apparently there is no predefined list available in .net.
I'd like to use a number of standard colors, e.g. something like red, green, blue, yellow, ... i.e. the typical colors consisting of 00 and FF components, followed by those with additional 7F components, ...
Is there a way to retrieve these "standard" colors or do I have to write the IEnumerable<Color>
myself?
Edit: This is a possible output for the RGB values.
Please note that order of sets matters in that the 00/FF enumeration has to be complete before 80 is added, and the 00/80/FF enumeration has to be complete before adding 40/B0, and so on. The order within a set does not matter (i.e. 00 FF 00 may come before 00 00 FF).
00 00 00 // start out with 00 and FF components
00 00 FF
00 FF 00
FF 00 00
FF FF 00
FF 00 FF
00 FF FF
FF FF FF
00 00 80 // ok, now add 80
00 80 00
...
80 80 80
FF 00 80
FF 80 00
FF 80 80
80 FF 00
80 FF 80
FF FF 80
...
// now add 40 and B0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
颜色
类上有许多预定义的 ARGB 颜色,颜色
结构。这些包含诸如Yellow
、White
、Green
等...如果您想要用户定义的系统颜色,您可以使用
SystemColors
类,其中包含 < code>ActiveBorder、WindowText
等...更新:
框架中没有任何内容可以按 ARGB 值对颜色进行排序,因为它没有多大意义
您可以使用Linq 按组件对颜色列表进行排序(
OrderBy
扩展方法)。The
Colors
class has a number of pre-defined ARGB colors on it, as does theColor
struct. These hold things likeYellow
,White
,Green
etc...If you want the user defined system colors, you can use the
SystemColors
class which has things likeActiveBorder
,WindowText
etc...Update:
There is nothing in the framework that sorts colors by their ARGB values as such, since it doesn't really make much sense
You can use Linq to sort a list of colors by their components (
OrderBy
extension method).也许, SystemColors 类适合您。
Probably, the SystemColors class is the right thing for you.
AFAIK“标准”颜色不等于基于您描述的模式的 RGB 值颜色。例如,紫色具有 #B803FF RGB 值(其中类似的“紫红色”具有 #FF00FF )。
AFAIK "Standard" colors are not equal to colors with RGB value based on patter that you described. For example purple color has #B803FF RGB value ( where similar 'fuchsia' has #FF00FF ).
这是生成序列的相当快的方法:
这当然可以改进。例如,应避免使用单独的 outR/G/B 变量,并且应通过 2*inc 从奇数(基于
inc
)值开始递增,以避免必须测试该值是否为之前已经生成了。使用此测试
会生成以下输出:
This is a reasonably fast way to generate the sequence:
This can certainly be improved. For instance, having a separate outR/G/B variable should be avoided, and incrementing should be via 2*inc starting from an odd (based on
inc
) value to avoid having to test if the value was already generated earlier.Using this test
the following output is generated: