Condividi tramite


Matrix Structure

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Represents a 3x3 affine transformation matrix used for transformations in two-dimensional space.

Namespace:  System.Windows.Media
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Structure Matrix _
    Implements IFormattable
public struct Matrix : IFormattable
<Matrix .../>
<object property="m11,m12,m21,m22,offsetX,offsetY"/>
- or -
<object property="m11 m12 m21 m22 offsetX offsetY"/>
-or-
<object property="Identity"/>

XAML Values

  • m11
    The numeric value in the first row and first column of this Matrix. For more information, see M11.

  • m12
    The numeric value in the first row and second column. For more information, see M12.

  • m21
    The numeric value in the second row and first column. For more information, see M21.

  • m22
    The numeric value in the second row and second column. For more information, see M22.

  • offsetX
    The numeric value in the third row and first column. For more information, see OffsetX.

  • offsetY
    The numeric value in the third row and second column. For more information, see OffsetY.

  • Identity
    The literal Identity value. See Identity.

The Matrix type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows Phone Matrix Initializes a Matrix structure.

Top

Properties

  Name Description
Public propertyStatic memberSupported by Silverlight for Windows Phone Identity Gets an identity Matrix.
Public propertySupported by Silverlight for Windows Phone IsIdentity Gets a value that indicates whether this Matrix structure is an identity matrix.
Public propertySupported by Silverlight for Windows Phone M11 Gets or sets the value of the first row and first column of this Matrix structure.
Public propertySupported by Silverlight for Windows Phone M12 Gets or sets the value of the first row and second column of this Matrix structure.
Public propertySupported by Silverlight for Windows Phone M21 Gets or sets the value of the second row and first column of this Matrix structure.
Public propertySupported by Silverlight for Windows Phone M22 Gets or sets the value of the second row and second column of this Matrix structure.
Public propertySupported by Silverlight for Windows Phone OffsetX Gets or sets the value of the third row and first column of this Matrix structure.
Public propertySupported by Silverlight for Windows Phone OffsetY Gets or sets the value of the third row and second column of this Matrix structure.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows Phone Equals(Matrix) Determines whether the specified Matrix structure is identical to this instance.
Public methodSupported by Silverlight for Windows Phone Equals(Object) Determines whether the specified Object is a Matrix structure that is identical to this Matrix. (Overrides ValueType.Equals(Object).)
Protected methodSupported by Silverlight for Windows Phone Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetHashCode Returns the hash code for this Matrix structure. (Overrides ValueType.GetHashCode().)
Public methodSupported by Silverlight for Windows Phone GetType Gets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone ToString() Creates a String representation of this Matrix structure. (Overrides ValueType.ToString().)
Public methodSupported by Silverlight for Windows Phone ToString(IFormatProvider) Creates a String representation of this Matrix structure with culture-specific formatting information.
Public methodSupported by Silverlight for Windows Phone Transform Transforms the specified point by the Matrix and returns the result.

Top

Operators

  Name Description
Public operatorStatic memberSupported by Silverlight for Windows Phone Equality Determines whether the two specified Matrix structures are identical.
Public operatorStatic memberSupported by Silverlight for Windows Phone Inequality Determines whether the two specified Matrix structures are not identical.

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows Phone IFormattable.ToString Infrastructure. For a description of this member, see ToString.

Top

Remarks

A 3x3 matrix is used for transformations in a two-dimensional x-y plane. Affine transformation matrices can be multiplied to form any number of linear transformations, such as rotation and skew (shear), followed by translation. An affine transformation matrix has its final column equal to (0, 0, 1), so only the members in the first two columns need to be specified. Note that vectors are expressed as row-vectors, not column vectors.

A Matrix is stored using row-major order and has the following structure:

The members in the last row, OffsetX and OffsetY, represent translation values.

In methods and properties, the transformation matrix is usually specified as a vector with only six members, as follows:

    (M11, M12, M21, M22, OffsetX, OffsetY)

Although you can use a Matrix structure directly to translate individual points, or with a MatrixTransform to transform objects, Silverlight also provides a set of classes that enable you to transform objects without working directly with matrices: RotateTransform, ScaleTransform, SkewTransform, and TranslateTransform.

Properties of a Matrix are animatable (as one or more DoubleAnimation animations or DoubleAnimationUsingKeyFrames).

A Matrix provides the property value for the MatrixTransform.Matrix property.

Related types can be used for transformation matrices in three-dimensional space and then used for a projection. See Matrix3D and Matrix3DProjection.

In the XAML syntax, either a comma or space can be used as a delimiter.

Examples

The following XAML defines a Matrix that provides data for a MatrixTransform applied to a rectangular shape. In this case, the matrix combines an offset (OffsetX and OffsetY) and a skew (M12). Note that this same effect could have been produced by combining a TranslateTransform and a SkewTransform. Whether to use a single Matrix or combinations of discrete transforms is a matter of coding style, the results are identical.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference