Пример #1
0
 /// <summary>
 /// Creates from a given color.
 /// </summary>
 /// <param name="color">The color.</param>
 /// <returns></returns>
 public static RgbColor FromHsbColor(
     HsbColor color)
 {
     return(color.ToRgbColor());
 }
Пример #2
0
    /// <summary>
    /// Converts <see cref="HsbColor"/> to <see cref="RgbColor"/>.
    /// </summary>
    /// <param name="hsb">The <see cref="HsbColor"/>.</param>
    /// <returns>A <see cref="RgbColor"/> equivalent.</returns>
    public static RgbColor HsbToRgb( 
      HsbColor hsb )
    {
      double red = 0, green = 0, blue = 0;

      double h = hsb.Hue;
      double s = ((double)hsb.Saturation) / 100;
      double b = ((double)hsb.Brightness) / 100;

      if ( s == 0 )
      {
        red = b;
        green = b;
        blue = b;
      }
      else
      {
        // the color wheel has six sectors.

        double sectorPosition = h / 60;
        var sectorNumber = (int)Math.Floor( sectorPosition );
        double fractionalSector = sectorPosition - sectorNumber;

        double p = b * (1 - s);
        double q = b * (1 - (s * fractionalSector));
        double t = b * (1 - (s * (1 - fractionalSector)));

        // Assign the fractional colors to r, g, and b
        // based on the sector the angle is in.
        switch ( sectorNumber )
        {
          case 0:
            red = b;
            green = t;
            blue = p;
            break;

          case 1:
            red = q;
            green = b;
            blue = p;
            break;

          case 2:
            red = p;
            green = b;
            blue = t;
            break;

          case 3:
            red = p;
            green = q;
            blue = b;
            break;

          case 4:
            red = t;
            green = p;
            blue = b;
            break;

          case 5:
            red = b;
            green = p;
            blue = q;
            break;
        }
      }

      var nRed = (int)Math.Round( red * 255 );
      var nGreen = (int)Math.Round( green * 255 );
      var nBlue = (int)Math.Round( blue * 255 );

      return new RgbColor( nRed, nGreen, nBlue );
    }
Пример #3
0
 /// <summary>
 /// Creates from a given color.
 /// </summary>
 /// <param name="color">The color.</param>
 /// <returns></returns>
 public static HslColor FromHsbColor( 
   HsbColor color )
 {
   return FromRgbColor( color.ToRgbColor() );
 }
Пример #4
0
        /// <summary>
        /// Converts <see cref="HsbColor"/> to <see cref="RgbColor"/>.
        /// </summary>
        /// <param name="hsb">The <see cref="HsbColor"/>.</param>
        /// <returns>A <see cref="RgbColor"/> equivalent.</returns>
        public static RgbColor HsbToRgb(
            HsbColor hsb)
        {
            double red = 0, green = 0, blue = 0;

            double h = hsb.Hue;
            double s = ((double)hsb.Saturation) / 100;
            double b = ((double)hsb.Brightness) / 100;

            if (s == 0)
            {
                red   = b;
                green = b;
                blue  = b;
            }
            else
            {
                // the color wheel has six sectors.

                double sectorPosition   = h / 60;
                var    sectorNumber     = (int)Math.Floor(sectorPosition);
                double fractionalSector = sectorPosition - sectorNumber;

                double p = b * (1 - s);
                double q = b * (1 - (s * fractionalSector));
                double t = b * (1 - (s * (1 - fractionalSector)));

                // Assign the fractional colors to r, g, and b
                // based on the sector the angle is in.
                switch (sectorNumber)
                {
                case 0:
                    red   = b;
                    green = t;
                    blue  = p;
                    break;

                case 1:
                    red   = q;
                    green = b;
                    blue  = p;
                    break;

                case 2:
                    red   = p;
                    green = b;
                    blue  = t;
                    break;

                case 3:
                    red   = p;
                    green = q;
                    blue  = b;
                    break;

                case 4:
                    red   = t;
                    green = p;
                    blue  = b;
                    break;

                case 5:
                    red   = b;
                    green = p;
                    blue  = q;
                    break;
                }
            }

            var nRed   = (int)Math.Round(red * 255);
            var nGreen = (int)Math.Round(green * 255);
            var nBlue  = (int)Math.Round(blue * 255);

            return(new RgbColor(nRed, nGreen, nBlue));
        }
Пример #5
0
 /// <summary>
 /// Creates from a given color.
 /// </summary>
 /// <param name="color">The color.</param>
 /// <returns></returns>
 public static HsbColor FromHsbColor(
     HsbColor color)
 {
     return(new HsbColor(color.Hue, color.Saturation, color.Brightness));
 }
Пример #6
0
		/// <summary>
		/// Creates from a given color.
		/// </summary>
		/// <param name="color">The color.</param>
		/// <returns></returns>
		public static RgbColor FromHsbColor(
			HsbColor color )
		{
			return color.ToRgbColor();
		}
Пример #7
0
 /// <summary>
 /// Creates from a given color.
 /// </summary>
 /// <param name="color">The color.</param>
 /// <returns></returns>
 public static HslColor FromHsbColor(
     HsbColor color)
 {
     return(FromRgbColor(color.ToRgbColor()));
 }
Пример #8
0
		/// <summary>
		/// Creates from a given color.
		/// </summary>
		/// <param name="color">The color.</param>
		/// <returns></returns>
		public static HsbColor FromHsbColor(
			HsbColor color )
		{
			return new HsbColor( color.Hue, color.Saturation, color.Brightness );
		}