/// <summary>
        /// Gets the color from the scale at position 'pos'.
        /// </summary>
        /// <remarks>If the position is outside the scale [0..1] only the fractional part
        /// is used (in other words the scale restarts for each integer-part).</remarks>
        /// <param name="pos">Position on scale between 0.0f and 1.0f</param>
        /// <returns>Color on scale</returns>
        public StyleColor GetColor(Single pos)
        {
            if (_colors.Length != _positions.Length)
            {
                throw (new ArgumentException("Colors and Positions arrays must be of equal length"));
            }

            if (_colors.Length < 2)
            {
                throw (new ArgumentException("At least two colors must be defined in the ColorBlend"));
            }

            if (_positions[0] != 0f)
            {
                throw (new ArgumentException("First position value must be 0.0f"));
            }

            if (_positions[_positions.Length - 1] != 1f)
            {
                throw (new ArgumentException("Last position value must be 1.0f"));
            }

            if (pos > 1 || pos < 0)
            {
                pos -= (Single)Math.Floor(pos);
            }

            Int32 i = 1;

            while (i < _positions.Length && _positions[i] < pos)
            {
                i++;
            }

            Single frac = (pos - _positions[i - 1]) / (_positions[i] - _positions[i - 1]);
            Int32  r    = (Int32)Math.Round((_colors[i - 1].R * (1 - frac) + _colors[i].R * frac));
            Int32  g    = (Int32)Math.Round((_colors[i - 1].G * (1 - frac) + _colors[i].G * frac));
            Int32  b    = (Int32)Math.Round((_colors[i - 1].B * (1 - frac) + _colors[i].B * frac));
            Int32  a    = (Int32)Math.Round((_colors[i - 1].A * (1 - frac) + _colors[i].A * frac));

            return(StyleColor.FromBgra(b, g, r, a));
        }
Beispiel #2
0
 public static StyleColor Convert(GdiColor color)
 {
     return(StyleColor.FromBgra(color.B, color.G, color.R, color.A));
 }