zoukankan      html  css  js  c++  java
  • LinearGradientBrush和GradientStop类

    LinearGradientBrush指的是一个线性的坡度类,用它和GradientStop类可以为一个矩形区域填充渐变的颜色。

    例如:

    <!-- 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>注意,(0,0)指的是矩形的左上角,(1,1)指的是矩形的右下角。所以颜色的渐变效果如下:GradientStop.jpg对应的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为(0,0.5),EndPoint为(1,0.5),如果要创建竖直方向的颜色渐变,设置StartPoint为(0.5,0),EndPoint为(0.5,1)。

  • 相关阅读:
    URAL-1998 The old Padawan 二分
    URAL-1997 Those are not the droids you're looking for 二分匹配
    URAL-1991 The battle near the swamp 水题
    URAL-1989 Subpalindromes 多项式Hash+树状数组
    URAL-1987 Nested Segments 线段树简单区间覆盖
    URAL-1981 Parallel and Perpendicular 水题
    k8s-api
    golang test模块
    k8s-calico
    docker设置proxy
  • 原文地址:https://www.cnblogs.com/bear831204/p/1310206.html
Copyright © 2011-2022 走看看