Exemplo n.º 1
0
        /// <summary>
        /// Converts color to hex code
        /// </summary>
        /// <param name="actColor">Color of the act.</param>
        /// <param name="format">The format.</param>
        /// <param name="includeSharpPrefix">if set to <c>true</c> it will include # prefix.</param>
        /// <returns></returns>
        public static String ColorToHex(this Color actColor, ColorHexFormats format = ColorHexFormats.ARGB, Boolean includeSharpPrefix = true)
        {
            StringBuilder sb = new StringBuilder();

            if (includeSharpPrefix)
            {
                sb.Append("#");
            }

            Char[] format_chars = format.ToString().ToCharArray();
            foreach (char ch in format_chars)
            {
                switch (ch)
                {
                case 'A':
                    sb.Append(actColor.A.ToString("X2"));     // IntToHex(actColor.R, 2));
                    break;

                case 'R':
                    sb.Append(actColor.R.ToString("X2"));
                    break;

                case 'G':
                    sb.Append(actColor.G.ToString("X2"));
                    break;

                case 'B':
                    sb.Append(actColor.B.ToString("X2"));
                    break;

                default:
                    break;
                }
            }

            return(sb.ToString()); //"#" +  + IntToHex(actColor.G, 2) + IntToHex(actColor.B, 2);
        }
Exemplo n.º 2
0
        public static String FormatHexColorTo(this String hexCode, ColorHexFormats format = ColorHexFormats.ARGB)
        {
            Color c = GetColor(hexCode);

            return(c.ColorToHex(format));
        }