예제 #1
0
        private static IMagickColor <QuantumType> CreateColor(string color)
        {
            Throw.IfNullOrEmpty(nameof(color), color);

            if (color[0] == '#')
            {
                if (!HexColor.TryParse(color, out var colors))
                {
                    throw new ArgumentException("Invalid hex value.", nameof(color));
                }

                if (colors.Count == 4)
                {
                    return(new MagickColor(colors[0], colors[1], colors[2], colors[3], Quantum.Max));
                }
            }

            throw new ArgumentException("Invalid color specified", nameof(color));
        }
예제 #2
0
        private void ParseHexColor(string color)
        {
            if (!HexColor.TryParse(color, out List <QuantumType> colors))
            {
                throw new ArgumentException("Invalid hex value.", nameof(color));
            }

            if (colors.Count == 1)
            {
                Initialize(colors[0], colors[0], colors[0], Quantum.Max);
            }
            else if (colors.Count == 3)
            {
                Initialize(colors[0], colors[1], colors[2], Quantum.Max);
            }
            else
            {
                Initialize(colors[0], colors[1], colors[2], colors[3]);
            }
        }