CSharp examples for System.Windows.Media:Brush
Creates a HSV brush.
using System.Windows.Media; using System.Windows; using System.Linq; using System.Collections.Generic; public class Main{ // http://en.wikipedia.org/wiki/HSL_and_HSV /// <summary> /// Creates a HSV brush. /// </summary> /// <param name="alpha">The opacity (0-1).</param> /// <param name="horizontal">if set to <c>true</c> [horizontal].</param> /// <returns>LinearGradientBrush.</returns> public static LinearGradientBrush CreateHsvBrush(double alpha = 1, bool horizontal = true) {//w w w . j ava 2 s. co m var a = (byte)(alpha * 255); var brush = new LinearGradientBrush { StartPoint = new Point(0, 0), EndPoint = horizontal ? new Point(1, 0) : new Point(0, 1) }; brush.GradientStops.Add(new GradientStop(Color.FromArgb(a, 0xff, 0x00, 0x00), 0.00)); brush.GradientStops.Add(new GradientStop(Color.FromArgb(a, 0xff, 0xff, 0x00), 0.17)); brush.GradientStops.Add(new GradientStop(Color.FromArgb(a, 0x00, 0xff, 0x00), 0.33)); brush.GradientStops.Add(new GradientStop(Color.FromArgb(a, 0x00, 0xff, 0xff), 0.50)); brush.GradientStops.Add(new GradientStop(Color.FromArgb(a, 0x00, 0x00, 0xff), 0.67)); brush.GradientStops.Add(new GradientStop(Color.FromArgb(a, 0xff, 0x00, 0xff), 0.84)); brush.GradientStops.Add(new GradientStop(Color.FromArgb(a, 0xff, 0x00, 0x00), 1.00)); return brush; } }