Share via


PathGradientBrush.SetBlendTriangularShape 方法

定義

使用中心色彩和一個環繞色彩的線型減少來建立漸層。

多載

SetBlendTriangularShape(Single)

使用中心色彩和一個環繞色彩的線型減少來建立漸層。

SetBlendTriangularShape(Single, Single)

使用中心色彩和每個環繞色彩的線型減少來建立漸層。

SetBlendTriangularShape(Single)

來源:
PathGradientBrush.cs
來源:
PathGradientBrush.cs
來源:
PathGradientBrush.cs

使用中心色彩和一個環繞色彩的線型減少來建立漸層。

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)

來源:
PathGradientBrush.cs
來源:
PathGradientBrush.cs
來源:
PathGradientBrush.cs

使用中心色彩和每個環繞色彩的線型減少來建立漸層。

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 Forms 使用,而且需要 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 有多個色彩,則陣列中的第一個色彩會用於結束色彩。 此陣列中指定的色彩是筆刷界限路徑上離散點所使用的色彩。

根據預設,當您從路徑漸層的界限移至中心點時,色彩會逐漸從界限色彩變更為中央色彩。 您可以藉由呼叫此方法,自定義界限和中央色彩的定位和混合。

適用於