Share via


PathGradientBrush.ScaleTransform 方法

定義

以指定的數量,縮放局部的幾何轉換。 這個方法預先規劃轉換的縮放矩陣。

多載

ScaleTransform(Single, Single)

以指定的數量,縮放局部的幾何轉換。 這個方法預先規劃轉換的縮放矩陣。

ScaleTransform(Single, Single, MatrixOrder)

依照指定的順序,根據指定的數量來縮放局部幾何轉換。

ScaleTransform(Single, Single)

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

以指定的數量,縮放局部的幾何轉換。 這個方法預先規劃轉換的縮放矩陣。

public:
 void ScaleTransform(float sx, float sy);
public void ScaleTransform (float sx, float sy);
member this.ScaleTransform : single * single -> unit
Public Sub ScaleTransform (sx As Single, sy As Single)

參數

sx
Single

在 X 軸方向的轉換縮放因數。

sy
Single

在 Y 軸方向的轉換縮放因數。

範例

如需範例,請參閱 ScaleTransform

適用於

ScaleTransform(Single, Single, MatrixOrder)

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

依照指定的順序,根據指定的數量來縮放局部幾何轉換。

public:
 void ScaleTransform(float sx, float sy, System::Drawing::Drawing2D::MatrixOrder order);
public void ScaleTransform (float sx, float sy, System.Drawing.Drawing2D.MatrixOrder order);
member this.ScaleTransform : single * single * System.Drawing.Drawing2D.MatrixOrder -> unit
Public Sub ScaleTransform (sx As Single, sy As Single, order As MatrixOrder)

參數

sx
Single

在 X 軸方向的轉換縮放因數。

sy
Single

在 Y 軸方向的轉換縮放因數。

order
MatrixOrder

MatrixOrder,指定要在之後或之前附加縮放矩陣。

範例

下列程式代碼範例是設計來搭配 Windows Forms 使用,而且需要 PaintEventArgse事件OnPaint物件。 代碼

  • 建立圖形路徑,並將矩形加入其中。

  • PathGradientBrush在此範例中,從路徑點建立 (,這些點會形成矩形,但可能是大部分的圖形) 。

  • 將中央色彩設定為紅色,並將周圍色彩設定為藍色。

  • PathGradientBrush 套用縮放轉換之前,先將 繪製到畫面。

  • 使用其 ScaleTransform 方法,將縮放轉換套用至筆刷。

  • TranslateTransform呼叫 方法來移動筆刷矩形,使其不會重疊稍早繪製到螢幕的矩形。

  • 將翻譯的筆刷矩形繪製到畫面。

請注意,底部矩形在 x 軸中長度為兩倍,如同在轉譯之前繪製的矩形。

public:
   void ScaleTransformExample( 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 transformation.
      e->Graphics->FillRectangle( myPGBrush, 10, 10, 200, 200 );

      // Scale by a factor of 2 in the x-axis by applying the scale
      // transform to the brush.
      myPGBrush->ScaleTransform( 2, 1, MatrixOrder::Append );

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

      // Draw the brush to the screen again after applying the
      // transforms.
      e->Graphics->FillRectangle( myPGBrush, 10, 10, 300, 300 );
   }
public void ScaleTransformExample(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 transformation.
    e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200);
             
    // Scale by a factor of 2 in the x-axis by applying the scale
    // transform to the brush.
    myPGBrush.ScaleTransform(2, 1, MatrixOrder.Append);
             
    // Move the brush down by 100 by Applying the translate
    // transform to the brush.
    myPGBrush.TranslateTransform(-100, 100, MatrixOrder.Append);
             
    // Draw the brush to the screen again after applying the
    // transforms.
    e.Graphics.FillRectangle(myPGBrush, 10, 10, 300, 300);
}
Public Sub ScaleTransformExample(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 transformation.
    e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200)

    ' Scale by a factor of 2 in the x-axis by applying the scale
    ' transform to the brush.
    myPGBrush.ScaleTransform(2, 1, MatrixOrder.Append)

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

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

適用於