Beispiel #1
0
 /// <summary>
 /// Creates a new <see cref="HsbColor"/> structure according to hue in degrees, saturation and brightness in percentage values.
 /// </summary>
 /// <param name="hue">The color's hue.</param>
 /// <param name="saturation">The saturation of the color.</param>
 /// <param name="brightness">The color's brightness.</param>
 public HsbColor(float hue, float saturation, float brightness)
 {
     if (hue < 0f || hue > 360f)
     {
         throw new ArgumentOutOfRangeException("Hue scale must be a value from 0.0 to 360.0");
     }
     if (saturation < 0f || saturation > 1f)
     {
         throw new ArgumentOutOfRangeException("Saturation scale must be a value from 0.0 to 1.0");
     }
     if (brightness < 0f || brightness > 1f)
     {
         throw new ArgumentOutOfRangeException("Brightness scale must be a value from 0.0 to 1.0");
     }
     if (brightness == 0f)
     {
         hue        = 0f;
         saturation = 0f;
     }
     else if (hue == 360f)
     {
         hue = 0;
     }
     _hsb = new HsbHash(hue, saturation, brightness);
     _h   = hue;
     _s   = saturation;
     _b   = brightness;
 }
Beispiel #2
0
        /// <summary>
        /// Creates a new <see cref="HsbColor"/> structure from a <seealso cref="Color"/> object.
        /// </summary>
        /// <param name="color">RGB color model from which to derive the hue, saturation and brightness.</param>
        public HsbColor(Color color)
        {
            float h, s, b;

            RGBtoHSB(color.R, color.G, color.B, out h, out s, out b);
            _h   = h;
            _s   = s;
            _b   = b;
            _hsb = new HsbHash(h, s, b);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new <see cref="HsbColor"/> structure from an RGB color model.
        /// </summary>
        /// <param name="other">RGB color model from which to derive the hue, saturation and brightness.</param>
        public HsbColor(RgbColor other)
        {
            float h, s, b;

            RGBFtoHSB(other.RScale, other.GScale, other.BScale, out h, out s, out b);
            _h   = h;
            _s   = s;
            _b   = b;
            _hsb = new HsbHash(h, s, b);
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new <see cref="HsbColor"/> structure according to hue, saturation and brightness in byte values.
        /// </summary>
        /// <param name="hue">The color's hue.</param>
        /// <param name="saturation">The saturation of the color.</param>
        /// <param name="brightness">The color's brightness.</param>
        public HsbColor(byte hue, byte saturation, byte brightness)
        {
            if (brightness == (byte)0)
            {
                hue        = (byte)0;
                saturation = (byte)0;
            }

            _hsb = new HsbHash(hue, saturation, brightness);
            _h   = (Convert.ToSingle(hue) * 36f) / 25.5f;
            _s   = Convert.ToSingle(saturation) / 255f;
            _b   = Convert.ToSingle(brightness) / 255f;
        }