語言

PathGradientBrush.SetBlendTriangularShape 方法

定義

產生一個中心色彩漸變,並線性衰減到周圍的顏色。

多載

名稱 Description
SetBlendTriangularShape(Single)

產生一個中心色彩漸變,並線性衰減到周圍的顏色。

SetBlendTriangularShape(Single, Single)

創造一個有中心色的漸層,並對周圍的每個顏色線性衰減。

SetBlendTriangularShape(Single)

來源:
PathGradientBrush.cs
來源:
PathGradientBrush.cs
來源:
PathGradientBrush.cs
來源:
PathGradientBrush.cs
來源:
PathGradientBrush.cs
來源:
PathGradientBrush.cs
來源:
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
來源:
PathGradientBrush.cs
來源:
PathGradientBrush.cs
來源:
PathGradientBrush.cs
來源:
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 事件物件。 此程式碼會執行下列動作:

  • 建立圖形路徑並加入一個矩形。

  • 從路徑點(在此例中,點形成矩形,但幾乎可以是任何形狀)建立 a 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 有多個顏色,則使用陣列中的第一個顏色作為結尾色。 此陣列中指定的顏色是用於筆刷邊界路徑上離散點的顏色。

預設情況下,當你從路徑漸層邊界移動到中心點時,顏色會逐漸從邊界色變成中心色。 你可以透過呼叫這個方法來自訂邊界和中心顏色的位置與混合。

適用於