/// <summary> /// Gets the inverted HSB color. /// </summary> /// <param name="input">The color to invert.</param> /// <returns>An inverted HSB struct.</returns> public static HSB GetInverted(HSB input) { float hue = input.Hue; if (hue < 0.5f) { hue += 0.5f; } else { hue -= 0.5f; } return(new HSB(hue * 360, input.Saturation100, input.Brightness100, input.A)); }
protected override void DrawHSBHue() { using (Graphics g = Graphics.FromImage(bmp)) { HSB color = new HSB(0f, 100, 100, SelectedColor.ARGB.A); for (int y = 0; y < clientHeight; y++) { color.Hue = (float)(1.0 - ((double)y / clientHeight)); using (Pen pen = new Pen(color)) { g.DrawLine(pen, 0, y, clientWidth, y); } } } }
// slider controls brightness // x = hue 0 -> 360 // y = saturation 100 -> 0 protected override void DrawHSBBrightness() { using (Graphics g = Graphics.FromImage(bmp)) { HSB start = new HSB(0, 100, (int)selectedColor.HSB.Brightness100, selectedColor.ARGB.A); HSB end = new HSB(0, 0, (int)selectedColor.HSB.Brightness100, selectedColor.ARGB.A); for (int x = 0; x < clientWidth; x++) { start.Hue = end.Hue = (float)((double)x / (clientHeight)); using (LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, 1, clientHeight), start, end, LinearGradientMode.Vertical)) { g.FillRectangle(brush, new Rectangle(x, 0, 1, clientHeight)); } } } }
// slider controls hue // x = saturation 0 -> 100 // y = brightness 100 -> 0 protected override void DrawHSBHue() { using (Graphics g = Graphics.FromImage(bmp)) { HSB start = new HSB((int)selectedColor.HSB.Hue360, 0, 0, selectedColor.ARGB.A); HSB end = new HSB((int)selectedColor.HSB.Hue360, 100, 0, selectedColor.ARGB.A); for (int y = 0; y < clientHeight; y++) { start.Brightness = end.Brightness = (float)(1.0 - ((double)y / (clientHeight))); using (LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, clientWidth, 1), start, end, LinearGradientMode.Horizontal)) { g.FillRectangle(brush, new Rectangle(0, y, clientWidth, 1)); } } } }
/// <summary> /// Inverts the current color. /// </summary> /// <returns>The inverted color.</returns> public HSB GetInverted() { return(HSB.GetInverted(this)); }
/// <summary> /// Convert the current color to a HSB color. /// </summary> /// <returns>An HSB representation of this color.</returns> public HSB ToHSB() { return(HSB.FromARGB(A, R, G, B)); }