PathGradientBrush.ScaleTransform 方法
定义
将局部几何转换缩放指定的量。Scales the local geometric transform by the specified amounts. 此方法预先计算转换的缩放矩阵。This method prepends the scaling matrix to the transform.
重载
| ScaleTransform(Single, Single) |
将局部几何转换缩放指定的量。Scales the local geometric transform by the specified amounts. 此方法预先计算转换的缩放矩阵。This method prepends the scaling matrix to the transform. |
| ScaleTransform(Single, Single, MatrixOrder) |
将局部几何转换以指定顺序缩放指定的量。Scales the local geometric transform by the specified amounts in the specified order. |
ScaleTransform(Single, Single)
将局部几何转换缩放指定的量。Scales the local geometric transform by the specified amounts. 此方法预先计算转换的缩放矩阵。This method prepends the scaling matrix to the transform.
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 轴方向上的变换比例因子。The transform scale factor in the x-axis direction.
- sy
- Single
Y 轴方向上的变换比例因子。The transform scale factor in the y-axis direction.
示例
有关示例,请参见 ScaleTransform。For an example, see ScaleTransform.
适用于
ScaleTransform(Single, Single, MatrixOrder)
将局部几何转换以指定顺序缩放指定的量。Scales the local geometric transform by the specified amounts in the specified order.
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 轴方向上的变换比例因子。The transform scale factor in the x-axis direction.
- sy
- Single
Y 轴方向上的变换比例因子。The transform scale factor in the y-axis direction.
- order
- MatrixOrder
一个 MatrixOrder,指定是在后面追加缩放矩阵还是在前面添加缩放矩阵。A MatrixOrder that specifies whether to append or prepend the scaling matrix.
示例
下面的代码示例旨在与 Windows 窗体一起使用,并且它需要 PaintEventArgs e 一个 OnPaint 事件对象。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, an OnPaint event object. 代码The code
创建图形路径并向其添加一个矩形。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.
在 PathGradientBrush 应用缩放变换之前,将绘制到屏幕。Draws the PathGradientBrush to the screen prior to applying the scale transform.
使用缩放转换将其方法应用于画笔 ScaleTransform 。Applies the scale transform to the brush by using its ScaleTransform 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 translated brush rectangle to the screen.
请注意,底部矩形的长度为 x 轴中的两倍,就是在转换前绘制的矩形。Notice that the bottom rectangle is twice as long in the x-axis as is the one drawn prior to the translation.
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