Matrix Matrix Matrix Matrix Class

定义

封装表示几何变换的 3x3 仿射矩阵。Encapsulates a 3-by-3 affine matrix that represents a geometric transform. 此类不能被继承。This class cannot be inherited.

public ref class Matrix sealed : MarshalByRefObject, IDisposable
public sealed class Matrix : MarshalByRefObject, IDisposable
type Matrix = class
    inherit MarshalByRefObject
    interface IDisposable
Public NotInheritable Class Matrix
Inherits MarshalByRefObject
Implements IDisposable
继承
实现

注解

GDI+GDI+中, 可以在Matrix对象中存储仿射转换。In GDI+GDI+ you can store an affine transformation in a Matrix object. 由于表示仿射转换的矩阵的第三列总是 (0, 0, 1), 因此, 在构造Matrix对象时, 只应在前两列中指定六个数字。Because the third column of a matrix that represents an affine transformation is always (0, 0, 1), you specify only the six numbers in the first two columns when you construct a Matrix object. 语句Matrix myMatrix = new Matrix(0, 1, -1, 0, 3, 4)构造如下图所示的矩阵。The statement Matrix myMatrix = new Matrix(0, 1, -1, 0, 3, 4) constructs the matrix shown in the following figure.

转换Transformations

复合转换Composite Transformations

复合转换是一系列转换, 一个后跟另一个。A composite transformation is a sequence of transformations, one followed by the other. 请考虑以下列表中的矩阵和转换:Consider the matrices and transformations in the following list:

矩阵 AMatrix A 旋转90度Rotate 90 degrees
矩阵 BMatrix B 在 x 方向上按系数2缩放Scale by a factor of 2 in the x direction
Matrix CMatrix C 在 y 方向上转换3个单位Translate 3 units in the y direction

如果我们从由矩阵 [2 1 1] 表示的点 (2, 1) 开始, 然后再乘以 A、B、C, 则点 (2, 1) 将按列出的顺序进行三次转换。If we start with the point (2, 1) - represented by the matrix [2 1 1] - and multiply by A, then B, then C, the point (2, 1) will undergo the three transformations in the order listed.

[2 1 1]ABC = [-2 5 1][2 1 1]ABC = [-2 5 1]

不是将复合转换的三个部分存储在三个单独的矩阵中, 而是可以将 A、B 和 C 相乘, 以获取存储整个复合转换的单个3×3矩阵。Rather than store the three parts of the composite transformation in three separate matrices, you can multiply A, B, and C together to get a single 3×3 matrix that stores the entire composite transformation. 假设 ABC = D。然后, 将一个点乘以 D, 就会得到与点相乘的结果, 然后再乘以 B, 然后按 C。Suppose ABC = D. Then a point multiplied by D gives the same result as a point multiplied by A, then B, then C.

[2 1 1]D = [-2 5 1][2 1 1]D = [-2 5 1]

下图显示了矩阵 A、B、C 和 D。The following illustration shows the matrices A, B, C, and D.

转换Transformations

复合转换的矩阵可以通过乘以单个变换矩阵来形成, 这意味着任何一系列仿射转换都可以存储在单个Matrix对象中。The fact that the matrix of a composite transformation can be formed by multiplying the individual transformation matrices means that any sequence of affine transformations can be stored in a single Matrix object.

注意

复合转换的顺序很重要。The order of a composite transformation is important. 通常, 旋转, 然后缩放, 然后平移与缩放、旋转和平移不同。In general, rotate, then scale, then translate is not the same as scale, then rotate, then translate. 同样, 矩阵相乘的顺序也非常重要。Similarly, the order of matrix multiplication is important. 通常, ABC 不同于背景。In general, ABC is not the same as BAC.

Scale RotateAt Shear Rotate Translate类提供若干用于生成复合转换的方法: Multiply、、、、和。 MatrixThe Matrix class provides several methods for building a composite transformation: Multiply, Rotate, RotateAt, Scale, Shear, and Translate. 下面的示例创建一个复合变换矩阵, 该矩阵首先旋转30度, 然后在 y 方向上按系数2缩放, 然后在 x 方向平移5个单位:The following example creates the matrix of a composite transformation that first rotates 30 degrees, then scales by a factor of 2 in the y direction, and then translates 5 units in the x direction:

Matrix myMatrix = new Matrix();
myMatrix.Rotate(30);
myMatrix.Scale(1, 2, MatrixOrder.Append);
myMatrix.Translate(5, 0, MatrixOrder.Append);
Dim myMatrix As New Matrix()
myMatrix.Rotate(30)
myMatrix.Scale(1, 2, MatrixOrder.Append)
myMatrix.Translate(5, 0, MatrixOrder.Append)

构造函数

Matrix() Matrix() Matrix() Matrix()

Matrix 类的一个新实例初始化为单位矩阵。Initializes a new instance of the Matrix class as the identity matrix.

Matrix(Rectangle, Point[]) Matrix(Rectangle, Point[]) Matrix(Rectangle, Point[]) Matrix(Rectangle, Point[])

Matrix 类的一个新实例初始化为指定矩形和点数组定义的几何变换。Initializes a new instance of the Matrix class to the geometric transform defined by the specified rectangle and array of points.

Matrix(RectangleF, PointF[]) Matrix(RectangleF, PointF[]) Matrix(RectangleF, PointF[]) Matrix(RectangleF, PointF[])

Matrix 类的一个新实例初始化为指定矩形和点数组定义的几何变换。Initializes a new instance of the Matrix class to the geometric transform defined by the specified rectangle and array of points.

Matrix(Single, Single, Single, Single, Single, Single) Matrix(Single, Single, Single, Single, Single, Single) Matrix(Single, Single, Single, Single, Single, Single) Matrix(Single, Single, Single, Single, Single, Single)

使用指定的元素初始化 Matrix 类的新实例。Initializes a new instance of the Matrix class with the specified elements.

属性

Elements Elements Elements Elements

获取一个浮点值数组,它表示该 Matrix 的元素。Gets an array of floating-point values that represents the elements of this Matrix.

IsIdentity IsIdentity IsIdentity IsIdentity

获取一个值,该值指示此 Matrix 是否是单位矩阵。Gets a value indicating whether this Matrix is the identity matrix.

IsInvertible IsInvertible IsInvertible IsInvertible

获取一个值,该值指示此 Matrix 是否可逆转。Gets a value indicating whether this Matrix is invertible.

OffsetX OffsetX OffsetX OffsetX

获取此 Matrix 的 x 转换值(dx 值,或第三行、第一列中的元素)。Gets the x translation value (the dx value, or the element in the third row and first column) of this Matrix.

OffsetY OffsetY OffsetY OffsetY

获取此 Matrix 的 y 转换值(dy 值,或第三行、第二列中的元素)。Gets the y translation value (the dy value, or the element in the third row and second column) of this Matrix.

方法

Clone() Clone() Clone() Clone()

创建此 Matrix 的一个精确副本。Creates an exact copy of this Matrix.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

释放此 Matrix 使用的所有资源。Releases all resources used by this Matrix.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

测试指定的对象是否是 Matrix 以及是否与此 Matrix 相同。Tests whether the specified object is a Matrix and is identical to this Matrix.

Finalize() Finalize() Finalize() Finalize()

在垃圾回收将某一对象回收前允许该对象尝试释放资源并执行其他清理操作。Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

返回哈希代码。Returns a hash code.

GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
Invert() Invert() Invert() Invert()

如果此 Matrix 是可逆转的,则进行逆转。Inverts this Matrix, if it is invertible.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
Multiply(Matrix) Multiply(Matrix) Multiply(Matrix) Multiply(Matrix)

通过预先计算指定的 Matrix,将此 Matrixmatrix 参数中指定的矩阵相乘。Multiplies this Matrix by the matrix specified in the matrix parameter, by prepending the specified Matrix.

Multiply(Matrix, MatrixOrder) Multiply(Matrix, MatrixOrder) Multiply(Matrix, MatrixOrder) Multiply(Matrix, MatrixOrder)

将此 Matrixmatrix 参数中指定的矩阵相乘,而且采用 order 参数中指定的顺序。Multiplies this Matrix by the matrix specified in the matrix parameter, and in the order specified in the order parameter.

Reset() Reset() Reset() Reset()

重置此 Matrix 得到单位矩阵的元素。Resets this Matrix to have the elements of the identity matrix.

Rotate(Single) Rotate(Single) Rotate(Single) Rotate(Single)

预先计算此 Matrix,沿原点并按指定角度顺时针旋转。Prepend to this Matrix a clockwise rotation, around the origin and by the specified angle.

Rotate(Single, MatrixOrder) Rotate(Single, MatrixOrder) Rotate(Single, MatrixOrder) Rotate(Single, MatrixOrder)

按照 angle 参数中指定的顺时针旋转量,对此 Matrix 沿原点(X 和 Y 坐标为零处)旋转。Applies a clockwise rotation of an amount specified in the angle parameter, around the origin (zero x and y coordinates) for this Matrix.

RotateAt(Single, PointF) RotateAt(Single, PointF) RotateAt(Single, PointF) RotateAt(Single, PointF)

沿 point 参数中指定的点并通过预先计算该旋转,来顺时针旋转此 MatrixApplies a clockwise rotation to this Matrix around the point specified in the point parameter, and by prepending the rotation.

RotateAt(Single, PointF, MatrixOrder) RotateAt(Single, PointF, MatrixOrder) RotateAt(Single, PointF, MatrixOrder) RotateAt(Single, PointF, MatrixOrder)

按指定的顺序,沿指定点顺时针旋转该 MatrixApplies a clockwise rotation about the specified point to this Matrix in the specified order.

Scale(Single, Single) Scale(Single, Single) Scale(Single, Single) Scale(Single, Single)

通过预先计算比例向量,将指定的比例向量应用到此 MatrixApplies the specified scale vector to this Matrix by prepending the scale vector.

Scale(Single, Single, MatrixOrder) Scale(Single, Single, MatrixOrder) Scale(Single, Single, MatrixOrder) Scale(Single, Single, MatrixOrder)

使用指定的顺序,将指定的比例向量(scaleXscaleY)应用到此 MatrixApplies the specified scale vector (scaleX and scaleY) to this Matrix using the specified order.

Shear(Single, Single) Shear(Single, Single) Shear(Single, Single) Shear(Single, Single)

通过预先计算切变变换,将指定的切变向量应用到此 MatrixApplies the specified shear vector to this Matrix by prepending the shear transformation.

Shear(Single, Single, MatrixOrder) Shear(Single, Single, MatrixOrder) Shear(Single, Single, MatrixOrder) Shear(Single, Single, MatrixOrder)

按指定的顺序,将指定的切变向量应用到此 MatrixApplies the specified shear vector to this Matrix in the specified order.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
TransformPoints(PointF[]) TransformPoints(PointF[]) TransformPoints(PointF[]) TransformPoints(PointF[])

对指定的点数组应用此 Matrix 所表示的几何变换。Applies the geometric transform represented by this Matrix to a specified array of points.

TransformPoints(Point[]) TransformPoints(Point[]) TransformPoints(Point[]) TransformPoints(Point[])

对指定的点数组应用此 Matrix 所表示的几何变换。Applies the geometric transform represented by this Matrix to a specified array of points.

TransformVectors(PointF[]) TransformVectors(PointF[]) TransformVectors(PointF[]) TransformVectors(PointF[])

将数组中的每个矢量与矩阵相乘。Multiplies each vector in an array by the matrix. 该矩阵的转换元素(第三行)被忽略。The translation elements of this matrix (third row) are ignored.

TransformVectors(Point[]) TransformVectors(Point[]) TransformVectors(Point[]) TransformVectors(Point[])

只将该 Matrix 的缩放和旋转成分应用到指定的点数组。Applies only the scale and rotate components of this Matrix to the specified array of points.

Translate(Single, Single) Translate(Single, Single) Translate(Single, Single) Translate(Single, Single)

通过预先计算转换向量,将指定的转换向量(offsetXoffsetY)应用到此 MatrixApplies the specified translation vector (offsetX and offsetY) to this Matrix by prepending the translation vector.

Translate(Single, Single, MatrixOrder) Translate(Single, Single, MatrixOrder) Translate(Single, Single, MatrixOrder) Translate(Single, Single, MatrixOrder)

按指定的顺序,将指定的转换向量应用到此 MatrixApplies the specified translation vector to this Matrix in the specified order.

VectorTransformPoints(Point[]) VectorTransformPoints(Point[]) VectorTransformPoints(Point[]) VectorTransformPoints(Point[])

将数组中的每个矢量与矩阵相乘。Multiplies each vector in an array by the matrix. 该矩阵的转换元素(第三行)被忽略。The translation elements of this matrix (third row) are ignored.

适用于

另请参阅