Ejemplo n.º 1
0
        static public RGBA FromHexa(string hexa)
        {
            string value = hexa;

            if (value.StartsWith("#"))
            {
                value = value.Substr(1);
            }

            if (value.Length == 3)
            {
                value = $"{value[0]}{value[0]}{value[1]}{value[1]}{value[2]}{value[2]}FF";
            }

            if (value.Length == 4)
            {
                value = $"{value[0]}{value[0]}{value[1]}{value[1]}{value[2]}{value[2]}{value[3]}{value[3]}";
            }

            if (value.Length == 6)
            {
                value += "FF";
            }

            byte r = Externals.NumberToByte("0x" + value.Substring(0, 2));
            byte g = Externals.NumberToByte("0x" + value.Substring(2, 2));
            byte b = Externals.NumberToByte("0x" + value.Substring(4, 2));
            byte a = Externals.NumberToByte("0x" + value.Substring(6, 2));

            return(FromRGB(r, g, b, a));
        }