LinearGradientBrush 类:渐变绘图

http://msdn.microsoft.com/zh-cn/library/vstudio/system.windows.media.lineargradientbrush(v=vs.110).aspx

 

 

LinearGradientBrush paints an area with a linear gradient." data-guid="72413fbb951f26d0e3835ff4a223f7b1">LinearGradientBrush 使用线性渐变绘制区域。 线性渐变沿直线定义渐变。 StartPoint and EndPoint properties of the linear gradient." data-guid="11c5f752fd5f527aad261279dc62750a">该直线的终点由线性渐变的 StartPoint 和EndPoint 属性定义。 LinearGradientBrush brush paints its GradientStops along this line." data-guid="ce7a76a60ebf6fc3bf1e222bd78d7e7d">LinearGradientBrush 画笔沿此直线绘制其 GradientStops

默认的线性渐变是沿对角方向进行的。 StartPoint of a linear gradient is (0,0), the upper-left corner of the area being painted, and its EndPoint is (1,1), the lower-right corner of the area being painted." data-guid="73e86742f527c909867132c87dd2d6ae">默认情况下,线性渐变的 StartPoint 是被绘制区域的左上角 (0,0),其 EndPoint 是被绘制区域的右下角 (1,1)。 所得渐变的颜色是沿着对角方向路径插入的。

下图演示对角渐变。 其中添加了一条线,用于突出显示渐变从起点到终点的内插路径。

对角方向的线性渐变


对角线方向线性渐变的渐变轴

下一幅插图显示的是同一线性渐变,但它具有突出显示的渐变停止点。

具有突出显示的渐变停止点的对角线性渐变

线性渐变中的渐变停止点

可以指定未完全填充所绘制区域的渐变轴。 SpreadMethod property determines how the remaining area is painted." data-guid="1efd405942f86c4148d8d7c7984f337b">出现这种情况时,SpreadMethod 属性确定其余区域的绘制方式。

Freezable 功能

LinearGradientBrush is a type of Freezable object and therefore can be frozen to improve performance." data-guid="9dfc8569a2fb7ff31408770d68e26ccf">LinearGradientBrush 是一种 Freezable 对象,因此可以将其冻结以提高性能。 Freezable features, such as freezing and cloning, see Freezable Objects Overview." data-guid="da9973886bc800bd65c5b2f3a4d54934">有关 Freezable 功能(例如冻结和克隆)的信息,请参见 Freezable 对象概述

LinearGradientBrush class to paint an area with a linear gradient." data-guid="98faeabb3a5ec42ccfa9ebaad548baf9">本示例演示如何使用 LinearGradientBrush 类来绘制带有线性渐变的区域。 Fill of a Rectangle is painted with a diagonal linear gradient that transitions from yellow to red to blue to lime green." data-guid="dde03396b3686b1578b579503a4aad72">在下面的示例中,Rectangle 的 Fill 是用从黄色依次过渡到红色、蓝色和浅绿色的对角线性渐变来绘制的。

<!-- This rectangle is painted with a diagonal linear gradient. -->
<Rectangle Width="200" Height="100">
  <Rectangle.Fill>
    <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
      <GradientStop Color="Yellow" Offset="0.0" />
      <GradientStop Color="Red" Offset="0.25" />
      <GradientStop Color="Blue" Offset="0.75" />
      <GradientStop Color="LimeGreen" Offset="1.0" />
    </LinearGradientBrush>
  </Rectangle.Fill>
</Rectangle>


C#
Rectangle diagonalFillRectangle = new Rectangle();
diagonalFillRectangle.Width = 200;
diagonalFillRectangle.Height = 100;

// Create a diagonal linear gradient with four stops.   
LinearGradientBrush myLinearGradientBrush =
    new LinearGradientBrush();
myLinearGradientBrush.StartPoint = new Point(0,0);
myLinearGradientBrush.EndPoint = new Point(1,1);
myLinearGradientBrush.GradientStops.Add(
    new GradientStop(Colors.Yellow, 0.0));
myLinearGradientBrush.GradientStops.Add(
    new GradientStop(Colors.Red, 0.25));                
myLinearGradientBrush.GradientStops.Add(
    new GradientStop(Colors.Blue, 0.75));        
myLinearGradientBrush.GradientStops.Add(
    new GradientStop(Colors.LimeGreen, 1.0));

// Use the brush to paint the rectangle.
diagonalFillRectangle.Fill = myLinearGradientBrush;


下图显示了上一示例创建的渐变。

对角线方向线性渐变

StartPoint and EndPoint of the LinearGradientBrush to (0,0.5) and (1,0.5)." data-guid="fc681462a9ebd62c3282081e16210388">若要创建水平线性渐变,请将 LinearGradientBrush 的 StartPoint 和 EndPoint 分别改为 (0,0.5) 和 (1,0.5)。 Rectangle is painted with a horizontal linear gradient." data-guid="735abd2c241f9ad0b75cfdcacf61e441">在下面的示例中,Rectangle 是用水平线性渐变来绘制的。

<!-- This rectangle is painted with a horizontal linear gradient. -->
<Rectangle Width="200" Height="100">
  <Rectangle.Fill>
    <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
      <GradientStop Color="Yellow" Offset="0.0" />
      <GradientStop Color="Red" Offset="0.25" />
      <GradientStop Color="Blue" Offset="0.75" />
      <GradientStop Color="LimeGreen" Offset="1.0" />
    </LinearGradientBrush>
  </Rectangle.Fill>
</Rectangle>


C#
            Rectangle horizontalFillRectangle = new Rectangle();
            horizontalFillRectangle.Width = 200;
            horizontalFillRectangle.Height = 100;

            // Create a horizontal linear gradient with four stops.   
            LinearGradientBrush myHorizontalGradient =
                new LinearGradientBrush();
            myHorizontalGradient.StartPoint = new Point(0,0.5);
            myHorizontalGradient.EndPoint = new Point(1,0.5);
            myHorizontalGradient.GradientStops.Add(
                new GradientStop(Colors.Yellow, 0.0));
            myHorizontalGradient.GradientStops.Add(
                new GradientStop(Colors.Red, 0.25));                
            myHorizontalGradient.GradientStops.Add(
                new GradientStop(Colors.Blue, 0.75));        
            myHorizontalGradient.GradientStops.Add(
                new GradientStop(Colors.LimeGreen, 1.0));

            // Use the brush to paint the rectangle.
            horizontalFillRectangle.Fill = myHorizontalGradient; 



下图显示了上一示例创建的渐变。

水平线性渐变

StartPoint and EndPoint of the LinearGradientBrush to (0.5,0) and (0.5,1)." data-guid="f5e3e01d8edc9184ce6d5671d9b8a607">若要创建垂直线性渐变,请将 LinearGradientBrush 的 StartPoint 和 EndPoint 分别改为 (0.5,0) 和 (0.5,1)。 Rectangle is painted with a vertical linear gradient." data-guid="e0fe6c0a0d122b67fdd09900aae576cd">在下面的示例中,Rectangle 是用垂直线性渐变来绘制的。

<!-- This rectangle is painted with a vertical gradient. -->
<Rectangle Width="200" Height="100">
  <Rectangle.Fill>
    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
      <GradientStop Color="Yellow" Offset="0.0" />
      <GradientStop Color="Red" Offset="0.25" />
      <GradientStop Color="Blue" Offset="0.75" />
      <GradientStop Color="LimeGreen" Offset="1.0" />
    </LinearGradientBrush>
  </Rectangle.Fill>
</Rectangle>


C#
Rectangle verticalFillRectangle = new Rectangle();
verticalFillRectangle.Width = 200;
verticalFillRectangle.Height = 100;

// Create a vertical linear gradient with four stops.   
LinearGradientBrush myVerticalGradient =
    new LinearGradientBrush();
myVerticalGradient.StartPoint = new Point(0.5,0);
myVerticalGradient.EndPoint = new Point(0.5,1);
myVerticalGradient.GradientStops.Add(
    new GradientStop(Colors.Yellow, 0.0));
myVerticalGradient.GradientStops.Add(
    new GradientStop(Colors.Red, 0.25));                
myVerticalGradient.GradientStops.Add(
    new GradientStop(Colors.Blue, 0.75));        
myVerticalGradient.GradientStops.Add(
    new GradientStop(Colors.LimeGreen, 1.0));

// Use the brush to paint the rectangle.
verticalFillRectangle.Fill = myVerticalGradient;  


下图显示了上一示例创建的渐变。

垂直线性渐变

此主题中的示例使用默认坐标系来设置起点和终点。 默认坐标系是相对于边界框的:0 表示边界框的 0%,1 表示边界框的 100%。 MappingMode property to the value BrushMappingMode.Absolute." data-guid="00c8ee91df694de604fbc1783e2d2951">可以通过将 MappingMode 属性设置为值 BrushMappingMode.Absolute 来更改此坐标系。 绝对坐标系与边界框不相关。 值直接在本地坐标系中解释。

Brushes Sample." data-guid="da7e90db39d227769799084a3cc70645">有关其他示例,请参见 Brushes Sample(画笔示例)。 Painting with Solid Colors and Gradients Overview." data-guid="5443f3d9e5f5ad23c2cfb724638a7555">有关渐变以及其他类型的画笔的更多信息,请参见使用纯色和渐变进行绘制概述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值