我正在尝试使用值0-1制作Hue滑块。
调整滑块时,应更改矩形的颜色。
它适用于Luminence和Saturation,但不适用于Hue。它始终保持相同的颜色。
色相
Luminence
我正在使用此HSL颜色类
https://richnewman.wordpress.com/about/code-listings-and-diagrams/hslcolor-class/
项目来源
https://www.dropbox.com/s/fzj2kd01ei933y0/HueSlider.zip?dl=0
C#
public MainWindow()
{
InitializeComponent();
baseColor = new System.Drawing.Color();
baseColor = System.Drawing.Color.FromArgb(255, 255, 0, 0); //red
}
System.Drawing.Color baseColor;
System.Drawing.Color newColor;
// Hue Slider
private void slHue_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
// Change Hue
newColor = Hue(baseColor, (double)slHue.Value);
// Fill Rectangle
Color brushColor = Color.FromArgb(newColor.A, newColor.R, newColor.G, newColor.B);
Brush brush = new SolidColorBrush(brushColor);
rectangle.Fill = brush;
// Display Values
tbxHue.Text = slHue.Value.ToString();
tbxRGB.Text = newColor.ToString();
}
// Change Hue
public System.Drawing.Color Hue(System.Drawing.Color color, double hue)
{
HSLColor hslColor = new HSLColor(color);
hslColor.Hue *= hue; // 0 to 1
return hslColor;
}
XAML
<Slider x:Name="slHue"
HorizontalAlignment="Left"
Margin="114,72,0,0"
VerticalAlignment="Top"
Width="99"
Minimum="0"
Maximum="1"
Value="0"
ValueChanged="slHue_ValueChanged"/>
<Rectangle x:Name="rectangle"
HorizontalAlignment="Left"
Height="100"
Margin="29,31,0,0"
Stroke="Black"
VerticalAlignment="Top"
Width="100">
</Rectangle>