PathGradientBrush.SetBlendTriangularShape 方法

定义

创建一个从中心色向周围色线性过渡的渐变过程。

重载

SetBlendTriangularShape(Single)

创建一个从中心色向周围色线性过渡的渐变过程。

SetBlendTriangularShape(Single, Single)

创建一个从中心色向各周围色线性过渡的渐变过程。

SetBlendTriangularShape(Single)

创建一个从中心色向周围色线性过渡的渐变过程。

public:
 void SetBlendTriangularShape(float focus);
public void SetBlendTriangularShape (float focus);
member this.SetBlendTriangularShape : single -> unit
Public Sub SetBlendTriangularShape (focus As Single)

参数

focus
Single

介于 0 和 1 之间的一个值,它指定沿路径中心到路径边界的任意半径向上中心色亮度最高的位置。 1(默认值)使最高亮度位于路径中心。

示例

有关示例,请参阅 SetBlendTriangularShape.

注解

如果数组中 SurroundColors 有多个颜色,则数组中的第一种颜色用于结束颜色。 此数组中指定的颜色用于画笔边界路径上的离散点。

适用于

SetBlendTriangularShape(Single, Single)

创建一个从中心色向各周围色线性过渡的渐变过程。

public:
 void SetBlendTriangularShape(float focus, float scale);
public void SetBlendTriangularShape (float focus, float scale);
member this.SetBlendTriangularShape : single * single -> unit
Public Sub SetBlendTriangularShape (focus As Single, scale As Single)

参数

focus
Single

介于 0 和 1 之间的一个值,它指定沿路径中心到路径边界的任意半径向上中心色亮度最高的位置。 1(默认值)使最高亮度位于路径中心。

scale
Single

介于 0 和 1 之间的一个值,它指定与边界色混合的中心色的最高亮度。 1 导致中心色的最高可能亮度,并且它是默认值。

示例

下面的代码示例设计用于Windows 窗体,并且需要PaintEventArgse一个OnPaint事件对象。 此代码执行以下操作:

  • 创建图形路径并为其添加一个矩形。

  • 从此示例中的路径点 (创建一个 PathGradientBrush 点,这些点构成一个矩形,但它可能是大多数形状) 。

  • 将中心颜色设置为红色,将周围颜色设置为蓝色。

  • PathGradientBrush在应用混合转换之前绘制到屏幕。

  • 使用 SetBlendTriangularShape 混合转换方法将混合转换应用于画笔。

  • TranslateTransform调用该方法来移动画笔矩形,使其不覆盖之前绘制到屏幕的矩形。

  • 绘制已转换画笔矩形以绘制到屏幕。

请注意,最大中心颜色 (红色) 位于从路径中心到路径边界的一半处。

public:
   void SetBlendTriangularShapeExample( PaintEventArgs^ e )
   {
      // Create a graphics path and add a rectangle.
      GraphicsPath^ myPath = gcnew GraphicsPath;
      Rectangle rect = Rectangle(100,20,100,50);
      myPath->AddRectangle( rect );

      // Get the path's array of points.
      array<PointF>^myPathPointArray = myPath->PathPoints;

      // Create a path gradient brush.
      PathGradientBrush^ myPGBrush = gcnew PathGradientBrush( myPathPointArray );

      // Set the color span.
      myPGBrush->CenterColor = Color::Red;
      array<Color>^ mySurroundColor = {Color::Blue};
      myPGBrush->SurroundColors = mySurroundColor;

      // Draw the brush to the screen prior to the blend.
      e->Graphics->FillRectangle( myPGBrush, 10, 10, 200, 200 );

      // Set the Blend factors.
      myPGBrush->SetBlendTriangularShape( 0.5f, 1.0f );

      // Move the brush down by 100 by Applying the translate
      // transform to the brush.
      myPGBrush->TranslateTransform( 0, 100, MatrixOrder::Append );

      // Draw the brush to the screen again after applying the
      // transforms.
      e->Graphics->FillRectangle( myPGBrush, 10, 10, 300, 300 );
   }
public void SetBlendTriangularShapeExample(PaintEventArgs e)
{
             
    // Create a graphics path and add a rectangle.
    GraphicsPath myPath = new GraphicsPath();
    Rectangle rect = new Rectangle(100, 20, 100, 50);
    myPath.AddRectangle(rect);
             
    // Get the path's array of points.
    PointF[] myPathPointArray = myPath.PathPoints;
             
    // Create a path gradient brush.
    PathGradientBrush myPGBrush = new
        PathGradientBrush(myPathPointArray);
             
    // Set the color span.
    myPGBrush.CenterColor = Color.Red;
    Color[] mySurroundColor = {Color.Blue};
    myPGBrush.SurroundColors = mySurroundColor;
             
    // Draw the brush to the screen prior to the blend.
    e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200);
             
    // Set the Blend factors.
    myPGBrush.SetBlendTriangularShape(0.5f, 1.0f);
             
    // Move the brush down by 100 by Applying the translate
    // transform to the brush.
    myPGBrush.TranslateTransform(0, 100, MatrixOrder.Append);
             
    // Draw the brush to the screen again after applying the
    // transforms.
    e.Graphics.FillRectangle(myPGBrush, 10, 10, 300, 300);
}
Public Sub SetBlendTriangularShapeExample(ByVal e As PaintEventArgs)

    ' Create a graphics path and add a rectangle.
    Dim myPath As New GraphicsPath
    Dim rect As New Rectangle(100, 20, 100, 50)
    myPath.AddRectangle(rect)

    ' Get the path's array of points.
    Dim myPathPointArray As PointF() = myPath.PathPoints

    ' Create a path gradient brush.
    Dim myPGBrush As New PathGradientBrush(myPathPointArray)

    ' Set the color span.
    myPGBrush.CenterColor = Color.Red
    Dim mySurroundColor As Color() = {Color.Blue}
    myPGBrush.SurroundColors = mySurroundColor

    ' Draw the brush to the screen prior to blend.
    e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200)

    ' Set the Blend factors.
    myPGBrush.SetBlendTriangularShape(0.5F, 1.0F)

    ' Move the brush down by 100 by Applying the translate
    ' transform to the brush.
    myPGBrush.TranslateTransform(0, 100, MatrixOrder.Append)

    ' Draw the brush to the screen again after applying the
    ' transforms.
    e.Graphics.FillRectangle(myPGBrush, 10, 10, 300, 300)
End Sub

注解

如果数组中 SurroundColors 有多个颜色,则数组中的第一种颜色用于结束颜色。 此数组中指定的颜色是用于画笔边界路径上离散点的颜色。

默认情况下,当从路径渐变的边界移动到中心点时,颜色会逐渐从边界颜色更改为中心颜色。 可以通过调用此方法来自定义边界和中心颜色的定位和混合。

适用于