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)。

  • 相关阅读:
    面试题15:链表中倒数第K个结点
    面试题31:连续子数组的最大和
    数据库索引实例
    面试题27:二叉搜索树与双向链表
    面试题28:字符串的排列
    java比较器Comparable接口和Comaprator接口
    面向对象知识汇总
    虚函数与纯虚函数
    Linux IO实时监控iostat命令详解
    hive GroupBy操作(翻译自Hive wiki)
  • 原文地址:https://www.cnblogs.com/bear831204/p/1310206.html
Copyright © 2011-2022 走看看