示例#1
0
        public static Color ToArgb(HsbColor source)
        {
            float fr = source.B;
            float fg = source.B;
            float fb = source.B;

            if (0F < source.S)
            {
                float h = source.H / 60F;
                int   i = (int)Floor(h);
                float f = h - i;

                float p = source.B * (1F - source.S);
                float q = source.B * (1F - source.S * f);
                float t = source.B * (1F - source.S * (1F - f));

                switch (i)
                {
                case 0:
                    fg = t;
                    fb = p;
                    break;

                case 1:
                    fr = q;
                    fb = p;
                    break;

                case 2:
                    fr = p;
                    fb = t;
                    break;

                case 3:
                    fr = p;
                    fg = q;
                    break;

                case 4:
                    fr = t;
                    fg = p;
                    break;

                case 5:
                    fg = p;
                    fb = q;
                    break;

                default:
                    throw new InvalidOperationException();                             // This must not happen.
                }
            }

            byte r = (byte)Max(Min(Round(fr * 255F), 255), 0);
            byte g = (byte)Max(Min(Round(fg * 255F), 255), 0);
            byte b = (byte)Max(Min(Round(fb * 255F), 255), 0);

            return(Color.FromArgb(source.A, r, g, b));
        }
        public static Color ToBrightened(this Color source, float factor)
        {
            if (factor <= 0F)
            {
                throw new ArgumentOutOfRangeException(nameof(factor));
            }

            var bridgeColor = HsbColor.FromArgb(source);

            bridgeColor.B = Min(1F, bridgeColor.B * factor);

            return(bridgeColor.ToArgb());
        }
 public static HsbColor ToAhsb(this Color source) =>
 HsbColor.FromArgb(source);
 public static HsbColor ToAhsb(this Color source)
 {
     return(HsbColor.FromArgb(source));
 }
示例#5
0
		public static Color ToArgb(HsbColor source)
		{
			float fr = source.B;
			float fg = source.B;
			float fb = source.B;

			if (0F < source.S)
			{
				float h = source.H / 60F;
				int i = (int)Floor(h);
				float f = h - i;

				float p = source.B * (1F - source.S);
				float q = source.B * (1F - source.S * f);
				float t = source.B * (1F - source.S * (1F - f));

				switch (i)
				{
					case 0:
						fg = t;
						fb = p;
						break;
					case 1:
						fr = q;
						fb = p;
						break;
					case 2:
						fr = p;
						fb = t;
						break;
					case 3:
						fr = p;
						fg = q;
						break;
					case 4:
						fr = t;
						fg = p;
						break;
					case 5:
						fg = p;
						fb = q;
						break;
					default:
						throw new InvalidOperationException(); // This must not happen.
				}
			}

			byte r = (byte)Max(Min(Round(fr * 255F), 255), 0);
			byte g = (byte)Max(Min(Round(fg * 255F), 255), 0);
			byte b = (byte)Max(Min(Round(fb * 255F), 255), 0);

			return Color.FromArgb(source.A, r, g, b);
		}