0
使用C#我怎样可以产生3点的梯度:WPF 3点梯度
- 白色(左)
- 蓝(右)
- 黑色(底部)
我现在做的方式是叠加2个渐变。
如果可能,我想将它简化为1个渐变。
C#
// White to Blue
LinearGradientBrush WhiteBlue = new LinearGradientBrush();
WhiteBlue.StartPoint = new System.Windows.Point(0, 0);
WhiteBlue.EndPoint = new System.Windows.Point(1, 0);
WhiteBlue.GradientStops.Add(new GradientStop(Color.FromArgb(255, 255, 255, 255), 0)); // white
WhiteBlue.GradientStops.Add(new GradientStop(Color.FromArgb(255, 255, 0, 0), 1)); // blue
rectangle1.Fill = WhiteBlue;
// Transparent to Black
LinearGradientBrush Black = new LinearGradientBrush();
Black.StartPoint = new System.Windows.Point(0, 0);
Black.EndPoint = new System.Windows.Point(0, 1);
Black.GradientStops.Add(new GradientStop(Color.FromArgb(0, 0, 0, 0), 0)); // transparent
Black.GradientStops.Add(new GradientStop(Color.FromArgb(255, 0, 0, 0), 1)); // black
rectangle2.Fill = Black;
XAML
<Rectangle x:Name="rectangle1"
HorizontalAlignment="Left"
Width="255"
Height="255"
VerticalAlignment="Top">
</Rectangle>
<Rectangle x:Name="rectangle2"
HorizontalAlignment="Left"
Width="255"
Height="255"
VerticalAlignment="Top">
</Rectangle>
看起来像你的解决方案已经是一个很好的方法:https://stackoverflow.com/questions/2925172/is-there-a-mergedgradientbrush-in-wpf – Fruchtzwerg
另一种方法是从原始像素数据创建一个位图和在Image控件中显示它。或者创建一个WritableBitmap并更新它的Buffer。 – Clemens