PathGradientBrush.SetBlendTriangularShape 方法

定义

创建一个从中心色向周围色线性过渡的渐变过程。Creates a gradient with a center color and a linear falloff to one surrounding color.

重载

SetBlendTriangularShape(Single)

创建一个从中心色向周围色线性过渡的渐变过程。Creates a gradient with a center color and a linear falloff to one surrounding color.

SetBlendTriangularShape(Single, Single)

创建一个从中心色向各周围色线性过渡的渐变过程。Creates a gradient with a center color and a linear falloff to each surrounding color.

SetBlendTriangularShape(Single)

创建一个从中心色向周围色线性过渡的渐变过程。Creates a gradient with a center color and a linear falloff to one surrounding color.

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 之间的一个值,它指定沿路径中心到路径边界的任意半径向上中心色亮度最高的位置。A value from 0 through 1 that specifies where, along any radial from the center of the path to the path's boundary, the center color will be at its highest intensity. 1(默认值)使最高亮度位于路径中心。A value of 1 (the default) places the highest intensity at the center of the path.

示例

有关示例,请参阅 SetBlendTriangularShape.For an example, see SetBlendTriangularShape.

注解

如果 SurroundColors 数组中有多个颜色,则使用数组中的第一种颜色作为结束颜色。If there is more than one color in the SurroundColors array, the first color in the array is used for the ending color. 此数组中指定的颜色用于画笔边界路径上的离散点。The colors specified in this array are used for discrete points on the brush's boundary path.

SetBlendTriangularShape(Single, Single)

创建一个从中心色向各周围色线性过渡的渐变过程。Creates a gradient with a center color and a linear falloff to each surrounding color.

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 之间的一个值,它指定沿路径中心到路径边界的任意半径向上中心色亮度最高的位置。A value from 0 through 1 that specifies where, along any radial from the center of the path to the path's boundary, the center color will be at its highest intensity. 1(默认值)使最高亮度位于路径中心。A value of 1 (the default) places the highest intensity at the center of the path.

scale
Single

介于 0 和 1 之间的一个值,它指定与边界色混合的中心色的最高亮度。A value from 0 through 1 that specifies the maximum intensity of the center color that gets blended with the boundary color. 1 导致中心色的最高可能亮度,并且它是默认值。A value of 1 causes the highest possible intensity of the center color, and it is the default value.

示例

下面的代码示例是为与 Windows 窗体一起使用而设计的,它需要 PaintEventArgseOnPaint 事件对象。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, an OnPaint event object. 该代码执行下列操作:The code performs the following actions:

  • 创建图形路径并向其添加一个矩形。Creates a graphics path and adds a rectangle to it.

  • 从路径点创建一个 PathGradientBrush (在此示例中,点构成一个矩形,但它可以是大多数形状)。Creates a PathGradientBrush from the path points (in this example, the points form a rectangle, but it could be most any shape).

  • 将中间颜色设置为红色,将周围颜色设置为蓝色。Sets the center color to red and the surrounding color to blue.

  • 在应用 blend 变换之前,将 PathGradientBrush 绘制到屏幕。Draws the PathGradientBrush to the screen prior to applying the blend transform.

  • 使用混合转换将其 SetBlendTriangularShape 方法应用于画笔。Applies the blend transform to the brush by using its SetBlendTriangularShape method.

  • 调用 TranslateTransform 方法来移动画笔矩形,使其不会覆盖之前绘制到屏幕的画笔。Calls the TranslateTransform method to move the brush rectangle such that it does not overlay the one drawn to the screen earlier.

  • 绘制转换后的画笔矩形。Draws the transformed-brush rectangle is drawn to the screen.

请注意,最大中心颜色(红色)从路径中心到路径边界的半个位置。Notice that the maximum center color (red) is located half way from the center of the path to the path boundary.

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 数组中有多个颜色,则使用数组中的第一种颜色作为结束颜色。If there is more than one color in the SurroundColors array, the first color in the array is used for the ending color. 此数组中指定的颜色是画笔边界路径上的离散点所使用的颜色。The colors specified in this array are colors used for discrete points on the brush's boundary path.

默认情况下,当你从路径渐变的边界移到中心点时,颜色将从边界逐渐变为中心色。By default, as you move from the boundary of a path gradient to the center point, the color changes gradually from the boundary color to the center color. 通过调用此方法,可以自定义边界和中心色的定位和混合。You can customize the positioning and blending of the boundary and center colors by calling this method.

适用于