GraphicsPath.Transform(Matrix) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将此转换矩阵应用于此 GraphicsPath。
public:
void Transform(System::Drawing::Drawing2D::Matrix ^ matrix);
public void Transform (System.Drawing.Drawing2D.Matrix matrix);
member this.Transform : System.Drawing.Drawing2D.Matrix -> unit
Public Sub Transform (matrix As Matrix)
参数
示例
下面的代码示例旨在与 Windows 窗体一起使用,它需要 PaintEventArgse
OnPaint 事件对象。 该代码执行以下操作:
创建路径并将省略号添加到路径。
绘制屏幕的路径。
创建转换矩阵以在 x 轴方向转换路径 100 个单位。
绘制屏幕的转换路径。
请注意,原始椭圆以黑色绘制,转换后的椭圆以红色绘制。
private:
void TransformExample( PaintEventArgs^ e )
{
// Create a path and add and ellipse.
GraphicsPath^ myPath = gcnew GraphicsPath;
myPath->AddEllipse( 0, 0, 100, 200 );
// Draw the starting position to screen.
e->Graphics->DrawPath( Pens::Black, myPath );
// Move the ellipse 100 points to the right.
Matrix^ translateMatrix = gcnew Matrix;
translateMatrix->Translate( 100, 0 );
myPath->Transform(translateMatrix);
// Draw the transformed ellipse to the screen.
e->Graphics->DrawPath( gcnew Pen( Color::Red,2.0f ), myPath );
}
private void TransformExample(PaintEventArgs e)
{
// Create a path and add and ellipse.
GraphicsPath myPath = new GraphicsPath();
myPath.AddEllipse(0, 0, 100, 200);
// Draw the starting position to screen.
e.Graphics.DrawPath(Pens.Black, myPath);
// Move the ellipse 100 points to the right.
Matrix translateMatrix = new Matrix();
translateMatrix.Translate(100, 0);
myPath.Transform(translateMatrix);
// Draw the transformed ellipse to the screen.
e.Graphics.DrawPath(new Pen(Color.Red, 2), myPath);
}
Public Sub TransformExample(ByVal e As PaintEventArgs)
' Create a path and add and ellipse.
Dim myPath As New GraphicsPath
myPath.AddEllipse(0, 0, 100, 200)
' Draw the starting position to screen.
e.Graphics.DrawPath(Pens.Black, myPath)
' Move the ellipse 100 points to the right.
Dim translateMatrix As New Matrix
translateMatrix.Translate(100, 0)
myPath.Transform(translateMatrix)
' Draw the transformed ellipse to the screen.
e.Graphics.DrawPath(New Pen(Color.Red, 2), myPath)
End Sub
注解
转换可以缩放、转换、旋转或倾斜 GraphicsPath。