Пример #1
0
        /// <summary>
        ///  Retrieve or create a name for the specified color.
        /// </summary>
        /// <param name="color">Color that may or may not have a associated name.</param>
        /// <returns>The color's name or a name created based upon the ARGB values.</returns>
        public static string GetName(this Color color)
        {
            if (color.IsEmpty)
            {
                return("Empty");
            }
            if (color.A == 0)
            {
                return(Color.Transparent.Name);
            }
            if (color.IsNamedColor)
            {
                return(color.Name);
            }
            var result = KnownColors.FirstOrDefault(c => c.R == color.R && c.G == color.G && c.B == color.B);

            return(!result.IsEmpty ? (color.A != 255 ? $"({color.A},{result.Name})" : result.Name) : (color.A != 255 ? $"({color.A},{color.R},{color.G},{color.B})" : $"({color.R},{color.G},{color.B})"));
        }