简体   繁体   English

获取RGB颜色

[英]Getting RGB colors

I want to get the rgb value of colors that are given as strings (accent 1, accent 2, ..., accent 6). 我想获取以字符串形式给出的颜色(重音1,重音2,...,重音6)的rgb值。 This is a table I got which describes each color visually. 是我得到的表格,可以直观地描述每种颜色。 I want to get each of those six values in format like this: #ff0000. 我想以如下格式获取这六个值中的每一个:#ff0000。

You can use this: 您可以使用此:

Accent 1: #4f81bd
Accent 2: #c0504d
Accent 3: #9bbb59
Accent 4: #8064a2
Accent 5: #4bacc6
Accent 6: #f79646

You'll need to look at how to get the Color object from these controls (do you have access to the controls? Hopefully there will be a way to get (and probably set) the color of the selected color). 您将需要研究如何从这些控件中获取Color对象(您可以访问这些控件吗? 希望将有一种方法来获取(并可能设置)所选颜色的颜色)。 If you have a list of these controls, you could create a Dictionary<string, YourColorControl> in this control and use this code; 如果您有这些控件的列表,则可以在此控件中创建Dictionary<string, YourColorControl>并使用此代码;

 Dictionary<string, YourColorControl> _colors = new Dictionary<string, YourColorControl>(); //find a way of filling this dictionary

string colorStr = "Accent 1";
if(!_colors.ContainsKey(colorStr)
    throw new Exception("No color with this name");

byte red = _colors[colorStr].R;
byte green = _colors[colorStr].G;
byte blue = _colors[colorStr].B;

你可以试试准备使用的解决方案喜欢这里

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

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