從System.Drawing.Color獲取所有的命名的標(biāo)準(zhǔn)顏色對應(yīng)的RGB值
System.Drawing.Color類中定義了一系列的命名顏色和一系列的有關(guān)顏色的方法。我們?nèi)绾螐倪@個類中提取它們呢?并且想知道他們這命名的顏色對應(yīng)的RGB是多少呢?
public static IList<Color> GetAllColors()
? ? ? ? {
? ? ? ? ? ? Type type = typeof(Color);
? ? ? ? ? ? PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Static);
? ? ? ? ? ? return props.Select(s => s.GetValue(null)).Select(s => (Color)s).ToList();
? ? ? ? }
這樣你就可以循環(huán)遍歷輸出它們的R、G、B值了。