Matrix Matrix Matrix Matrix Class

定義

封裝代表幾何轉換的 3 乘 3 仿射矩陣。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:

矩陣的Matrix A 旋轉 90 度Rotate 90 degrees
矩陣 BMatrix B 在 x 方向的 2 倍縮放Scale by a factor of 2 in the x direction
矩陣 CMatrix C 轉譯在 y 方向的 3 個單位Translate 3 units in the y direction

如果我們以代表矩陣 [2 1 1]-的指標 (2,1)-開頭,並乘上,然後 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 點會給予相同的結果為點乘以 A,然後 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.

Matrix類別提供多種方法來建置複合轉換: MultiplyRotateRotateAtScaleShear,和TranslateThe 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 類別的新執行個體做為識別 (Identity) 矩陣。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)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。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()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。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()

如果可反轉,則反轉這個 MatrixInverts this Matrix, if it is invertible.

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

建立目前 Object 的淺層複本 (Shallow Copy)。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,將這個 Matrix 乘以 matrix 參數中所指定的矩陣。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)

將這個 Matrix 乘以 matrix 參數中所指定的矩陣,並且依據 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)

以這個 Matrix 的原點 (X 座標和 Y 座標都為 0) 為中心,套用 angle 參數中指定的順時針旋轉量。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.

適用於

另請參閱