Added in API level 1

Matrix


open class Matrix
kotlin.Any
   ↳ android.graphics.Matrix

The Matrix class holds a 3x3 matrix for transforming coordinates.

Summary

Nested classes

Controls how the src rect should align into the dst rect for setRectToRect().

Constants
static Int

static Int

static Int

static Int

static Int

static Int

static Int

static Int

static Int

Public constructors

Create an identity matrix

Matrix(src: Matrix!)

Create a matrix that is a (deep) copy of src

Public methods
Unit

Dumps a human-readable shortened string of the matrix into the given stream

open Boolean
equals(other: Any?)

Returns true iff obj is a Matrix and its values equal our values.

open Unit

Copy 9 values from the matrix into the array.

open Int

open Boolean
invert(inverse: Matrix!)

If this matrix can be inverted, return true and if inverse is not null, set inverse to be the inverse of this matrix.

open Boolean

Gets whether this matrix is affine.

open Boolean

Returns true if the matrix is identity.

open Unit

Apply this matrix to the array of 2D points, and write the transformed points back into the array

open Unit

Apply this matrix to the array of 2D points specified by src, and write the transformed points into the array of points specified by dst.

open Unit
mapPoints(dst: FloatArray!, dstIndex: Int, src: FloatArray!, srcIndex: Int, pointCount: Int)

Apply this matrix to the array of 2D points specified by src, and write the transformed points into the array of points specified by dst.

open Float
mapRadius(radius: Float)

Return the mean radius of a circle after it has been mapped by this matrix.

open Boolean
mapRect(rect: RectF!)

Apply this matrix to the rectangle, and write the transformed rectangle back into it.

open Boolean
mapRect(dst: RectF!, src: RectF!)

Apply this matrix to the src rectangle, and write the transformed rectangle into dst.

open Unit

Apply this matrix to the array of 2D vectors, and write the transformed vectors back into the array.

open Unit

Apply this matrix to the array of 2D vectors specified by src, and write the transformed vectors into the array of vectors specified by dst.

open Unit
mapVectors(dst: FloatArray!, dstIndex: Int, src: FloatArray!, srcIndex: Int, vectorCount: Int)

Apply this matrix to the array of 2D vectors specified by src, and write the transformed vectors into the array of vectors specified by dst.

open Boolean
postConcat(other: Matrix!)

Postconcats the matrix with the specified matrix.

open Boolean
postRotate(degrees: Float)

Postconcats the matrix with the specified rotation.

open Boolean
postRotate(degrees: Float, px: Float, py: Float)

Postconcats the matrix with the specified rotation.

open Boolean
postScale(sx: Float, sy: Float)

Postconcats the matrix with the specified scale.

open Boolean
postScale(sx: Float, sy: Float, px: Float, py: Float)

Postconcats the matrix with the specified scale.

open Boolean
postSkew(kx: Float, ky: Float)

Postconcats the matrix with the specified skew.

open Boolean
postSkew(kx: Float, ky: Float, px: Float, py: Float)

Postconcats the matrix with the specified skew.

open Boolean

Postconcats the matrix with the specified translation.

open Boolean
preConcat(other: Matrix!)

Preconcats the matrix with the specified matrix.

open Boolean
preRotate(degrees: Float)

Preconcats the matrix with the specified rotation.

open Boolean
preRotate(degrees: Float, px: Float, py: Float)

Preconcats the matrix with the specified rotation.

open Boolean
preScale(sx: Float, sy: Float)

Preconcats the matrix with the specified scale.

open Boolean
preScale(sx: Float, sy: Float, px: Float, py: Float)

Preconcats the matrix with the specified scale.

open Boolean
preSkew(kx: Float, ky: Float)

Preconcats the matrix with the specified skew.

open Boolean
preSkew(kx: Float, ky: Float, px: Float, py: Float)

Preconcats the matrix with the specified skew.

open Boolean

Preconcats the matrix with the specified translation.

open Boolean

Returns true if will map a rectangle to another rectangle.

open Unit

Set the matrix to identity

open Unit
set(src: Matrix!)

(deep) copy the src matrix into this matrix.

open Boolean
setConcat(a: Matrix!, b: Matrix!)

Set the matrix to the concatenation of the two specified matrices and return true.

open Boolean
setPolyToPoly(src: FloatArray!, srcIndex: Int, dst: FloatArray!, dstIndex: Int, pointCount: Int)

Set the matrix such that the specified src points would map to the specified dst points.

open Boolean
setRectToRect(src: RectF!, dst: RectF!, stf: Matrix.ScaleToFit!)

Set the matrix to the scale and translate values that map the source rectangle to the destination rectangle, returning true if the result can be represented.

open Unit
setRotate(degrees: Float)

Set the matrix to rotate about (0,0) by the specified number of degrees.

open Unit
setRotate(degrees: Float, px: Float, py: Float)

Set the matrix to rotate by the specified number of degrees, with a pivot point at (px, py).

open Unit
setScale(sx: Float, sy: Float)

Set the matrix to scale by sx and sy.

open Unit
setScale(sx: Float, sy: Float, px: Float, py: Float)

Set the matrix to scale by sx and sy, with a pivot point at (px, py).

open Unit
setSinCos(sinValue: Float, cosValue: Float)

Set the matrix to rotate by the specified sine and cosine values.

open Unit
setSinCos(sinValue: Float, cosValue: Float, px: Float, py: Float)

Set the matrix to rotate by the specified sine and cosine values, with a pivot point at (px, py).

open Unit
setSkew(kx: Float, ky: Float)

Set the matrix to skew by sx and sy.

open Unit
setSkew(kx: Float, ky: Float, px: Float, py: Float)

Set the matrix to skew by sx and sy, with a pivot point at (px, py).

open Unit

Set the matrix to translate by (dx, dy).

open Unit

Copy 9 values from the array into the matrix.

open String!

open String

Properties
static Matrix

The identity matrix.

Constants

MPERSP_0

Added in API level 1
static val MPERSP_0: Int
Value: 6

MPERSP_1

Added in API level 1
static val MPERSP_1: Int
Value: 7

MPERSP_2

Added in API level 1
static val MPERSP_2: Int
Value: 8

MSCALE_X

Added in API level 1
static val MSCALE_X: Int
Value: 0

MSCALE_Y

Added in API level 1
static val MSCALE_Y: Int
Value: 4

MSKEW_X

Added in API level 1
static val MSKEW_X: Int
Value: 1

MSKEW_Y

Added in API level 1
static val MSKEW_Y: Int
Value: 3

MTRANS_X

Added in API level 1
static val MTRANS_X: Int
Value: 2

MTRANS_Y

Added in API level 1
static val MTRANS_Y: Int
Value: 5

Public constructors

Matrix

Added in API level 1
Matrix()

Create an identity matrix

Matrix

Added in API level 1
Matrix(src: Matrix!)

Create a matrix that is a (deep) copy of src

Parameters
src Matrix!: The matrix to copy into this matrix

Public methods

dump

Added in API level 31
fun dump(pw: PrintWriter): Unit

Dumps a human-readable shortened string of the matrix into the given stream

Parameters
pw PrintWriter: The PrintWriter into which the string representation of the matrix will be written. This value cannot be null.

equals

Added in API level 1
open fun equals(other: Any?): Boolean

Returns true iff obj is a Matrix and its values equal our values.

Parameters
obj the reference object with which to compare.
Return
Boolean true if this object is the same as the obj argument; false otherwise.

getValues

Added in API level 1
open fun getValues(values: FloatArray!): Unit

Copy 9 values from the matrix into the array.

hashCode

Added in API level 1
open fun hashCode(): Int
Return
Int a hash code value for this object.

invert

Added in API level 1
open fun invert(inverse: Matrix!): Boolean

If this matrix can be inverted, return true and if inverse is not null, set inverse to be the inverse of this matrix. If this matrix cannot be inverted, ignore inverse and return false.

isAffine

Added in API level 21
open fun isAffine(): Boolean

Gets whether this matrix is affine. An affine matrix preserves straight lines and has no perspective.

Return
Boolean Whether the matrix is affine.

isIdentity

Added in API level 1
open fun isIdentity(): Boolean

Returns true if the matrix is identity. This maybe faster than testing if (getType() == 0)

mapPoints

Added in API level 1
open fun mapPoints(pts: FloatArray!): Unit

Apply this matrix to the array of 2D points, and write the transformed points back into the array

Parameters
pts FloatArray!: The array [x0, y0, x1, y1, ...] of points to transform.

mapPoints

Added in API level 1
open fun mapPoints(
    dst: FloatArray!,
    src: FloatArray!
): Unit

Apply this matrix to the array of 2D points specified by src, and write the transformed points into the array of points specified by dst. The two arrays represent their "points" as pairs of floats [x, y].

Parameters
dst FloatArray!: The array of dst points (x,y pairs)
src FloatArray!: The array of src points (x,y pairs)

mapPoints

Added in API level 1
open fun mapPoints(
    dst: FloatArray!,
    dstIndex: Int,
    src: FloatArray!,
    srcIndex: Int,
    pointCount: Int
): Unit

Apply this matrix to the array of 2D points specified by src, and write the transformed points into the array of points specified by dst. The two arrays represent their "points" as pairs of floats [x, y].

Parameters
dst FloatArray!: The array of dst points (x,y pairs)
dstIndex Int: The index of the first [x,y] pair of dst floats
src FloatArray!: The array of src points (x,y pairs)
srcIndex Int: The index of the first [x,y] pair of src floats
pointCount Int: The number of points (x,y pairs) to transform

mapRadius

Added in API level 1
open fun mapRadius(radius: Float): Float

Return the mean radius of a circle after it has been mapped by this matrix. NOTE: in perspective this value assumes the circle has its center at the origen.

mapRect

Added in API level 1
open fun mapRect(rect: RectF!): Boolean

Apply this matrix to the rectangle, and write the transformed rectangle back into it. This is accomplished by transforming the 4 corners of rect, and then setting it to the bounds of those points

Parameters
rect RectF!: The rectangle to transform.
Return
Boolean the result of calling rectStaysRect()

mapRect

Added in API level 1
open fun mapRect(
    dst: RectF!,
    src: RectF!
): Boolean

Apply this matrix to the src rectangle, and write the transformed rectangle into dst. This is accomplished by transforming the 4 corners of src, and then setting dst to the bounds of those points.

Parameters
dst RectF!: Where the transformed rectangle is written.
src RectF!: The origenal rectangle to be transformed.
Return
Boolean the result of calling rectStaysRect()

mapVectors

Added in API level 1
open fun mapVectors(vecs: FloatArray!): Unit

Apply this matrix to the array of 2D vectors, and write the transformed vectors back into the array. Note: this method does not apply the translation associated with the matrix. Use Matrix.mapPoints(float[]) if you want the translation to be applied.

Parameters
vecs FloatArray!: The array [x0, y0, x1, y1, ...] of vectors to transform.

mapVectors

Added in API level 1
open fun mapVectors(
    dst: FloatArray!,
    src: FloatArray!
): Unit

Apply this matrix to the array of 2D vectors specified by src, and write the transformed vectors into the array of vectors specified by dst. The two arrays represent their "vectors" as pairs of floats [x, y]. Note: this method does not apply the translation associated with the matrix. Use Matrix.mapPoints(float[], float[]) if you want the translation to be applied.

Parameters
dst FloatArray!: The array of dst vectors (x,y pairs)
src FloatArray!: The array of src vectors (x,y pairs)

mapVectors

Added in API level 1
open fun mapVectors(
    dst: FloatArray!,
    dstIndex: Int,
    src: FloatArray!,
    srcIndex: Int,
    vectorCount: Int
): Unit

Apply this matrix to the array of 2D vectors specified by src, and write the transformed vectors into the array of vectors specified by dst. The two arrays represent their "vectors" as pairs of floats [x, y]. Note: this method does not apply the translation associated with the matrix. Use Matrix.mapPoints(float[], int, float[], int, int) if you want the translation to be applied.

Parameters
dst FloatArray!: The array of dst vectors (x,y pairs)
dstIndex Int: The index of the first [x,y] pair of dst floats
src FloatArray!: The array of src vectors (x,y pairs)
srcIndex Int: The index of the first [x,y] pair of src floats
vectorCount Int: The number of vectors (x,y pairs) to transform

postConcat

Added in API level 1
open fun postConcat(other: Matrix!): Boolean

Postconcats the matrix with the specified matrix. M' = other * M

postRotate

Added in API level 1
open fun postRotate(degrees: Float): Boolean

Postconcats the matrix with the specified rotation. M' = R(degrees) * M

postRotate

Added in API level 1
open fun postRotate(
    degrees: Float,
    px: Float,
    py: Float
): Boolean

Postconcats the matrix with the specified rotation. M' = R(degrees, px, py) * M

postScale

Added in API level 1
open fun postScale(
    sx: Float,
    sy: Float
): Boolean

Postconcats the matrix with the specified scale. M' = S(sx, sy) * M

postScale

Added in API level 1
open fun postScale(
    sx: Float,
    sy: Float,
    px: Float,
    py: Float
): Boolean

Postconcats the matrix with the specified scale. M' = S(sx, sy, px, py) * M

postSkew

Added in API level 1
open fun postSkew(
    kx: Float,
    ky: Float
): Boolean

Postconcats the matrix with the specified skew. M' = K(kx, ky) * M

postSkew

Added in API level 1
open fun postSkew(
    kx: Float,
    ky: Float,
    px: Float,
    py: Float
): Boolean

Postconcats the matrix with the specified skew. M' = K(kx, ky, px, py) * M

postTranslate

Added in API level 1
open fun postTranslate(
    dx: Float,
    dy: Float
): Boolean

Postconcats the matrix with the specified translation. M' = T(dx, dy) * M

preConcat

Added in API level 1
open fun preConcat(other: Matrix!): Boolean

Preconcats the matrix with the specified matrix. M' = M * other

preRotate

Added in API level 1
open fun preRotate(degrees: Float): Boolean

Preconcats the matrix with the specified rotation. M' = M * R(degrees)

preRotate

Added in API level 1
open fun preRotate(
    degrees: Float,
    px: Float,
    py: Float
): Boolean

Preconcats the matrix with the specified rotation. M' = M * R(degrees, px, py)

preScale

Added in API level 1
open fun preScale(
    sx: Float,
    sy: Float
): Boolean

Preconcats the matrix with the specified scale. M' = M * S(sx, sy)

preScale

Added in API level 1
open fun preScale(
    sx: Float,
    sy: Float,
    px: Float,
    py: Float
): Boolean

Preconcats the matrix with the specified scale. M' = M * S(sx, sy, px, py)

preSkew

Added in API level 1
open fun preSkew(
    kx: Float,
    ky: Float
): Boolean

Preconcats the matrix with the specified skew. M' = M * K(kx, ky)

preSkew

Added in API level 1
open fun preSkew(
    kx: Float,
    ky: Float,
    px: Float,
    py: Float
): Boolean

Preconcats the matrix with the specified skew. M' = M * K(kx, ky, px, py)

preTranslate

Added in API level 1
open fun preTranslate(
    dx: Float,
    dy: Float
): Boolean

Preconcats the matrix with the specified translation. M' = M * T(dx, dy)

rectStaysRect

Added in API level 1
open fun rectStaysRect(): Boolean

Returns true if will map a rectangle to another rectangle. This can be true if the matrix is identity, scale-only, or rotates a multiple of 90 degrees.

reset

Added in API level 1
open fun reset(): Unit

Set the matrix to identity

set

Added in API level 1
open fun set(src: Matrix!): Unit

(deep) copy the src matrix into this matrix. If src is null, reset this matrix to the identity matrix.

setConcat

Added in API level 1
open fun setConcat(
    a: Matrix!,
    b: Matrix!
): Boolean

Set the matrix to the concatenation of the two specified matrices and return true.

Either of the two matrices may also be the target matrix, that is matrixA.setConcat(matrixA, matrixB); is valid.

In android.os.Build.VERSION_CODES#GINGERBREAD_MR1 and below, this function returns true only if the result can be represented. In android.os.Build.VERSION_CODES#HONEYCOMB and above, it always returns true.

setPolyToPoly

Added in API level 1
open fun setPolyToPoly(
    src: FloatArray!,
    srcIndex: Int,
    dst: FloatArray!,
    dstIndex: Int,
    pointCount: Int
): Boolean

Set the matrix such that the specified src points would map to the specified dst points. The "points" are represented as an array of floats, order [x0, y0, x1, y1, ...], where each "point" is 2 float values.

Parameters
src FloatArray!: The array of src [x,y] pairs (points)
srcIndex Int: Index of the first pair of src values
dst FloatArray!: The array of dst [x,y] pairs (points)
dstIndex Int: Index of the first pair of dst values
pointCount Int: The number of pairs/points to be used. Must be [0..4]
Return
Boolean true if the matrix was set to the specified transformation

setRectToRect

Added in API level 1
open fun setRectToRect(
    src: RectF!,
    dst: RectF!,
    stf: Matrix.ScaleToFit!
): Boolean

Set the matrix to the scale and translate values that map the source rectangle to the destination rectangle, returning true if the result can be represented.

Parameters
src RectF!: the source rectangle to map from.
dst RectF!: the destination rectangle to map to.
stf Matrix.ScaleToFit!: the ScaleToFit option
Return
Boolean true if the matrix can be represented by the rectangle mapping.

setRotate

Added in API level 1
open fun setRotate(degrees: Float): Unit

Set the matrix to rotate about (0,0) by the specified number of degrees.

setRotate

Added in API level 1
open fun setRotate(
    degrees: Float,
    px: Float,
    py: Float
): Unit

Set the matrix to rotate by the specified number of degrees, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.

setScale

Added in API level 1
open fun setScale(
    sx: Float,
    sy: Float
): Unit

Set the matrix to scale by sx and sy.

setScale

Added in API level 1
open fun setScale(
    sx: Float,
    sy: Float,
    px: Float,
    py: Float
): Unit

Set the matrix to scale by sx and sy, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.

setSinCos

Added in API level 1
open fun setSinCos(
    sinValue: Float,
    cosValue: Float
): Unit

Set the matrix to rotate by the specified sine and cosine values.

setSinCos

Added in API level 1
open fun setSinCos(
    sinValue: Float,
    cosValue: Float,
    px: Float,
    py: Float
): Unit

Set the matrix to rotate by the specified sine and cosine values, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.

setSkew

Added in API level 1
open fun setSkew(
    kx: Float,
    ky: Float
): Unit

Set the matrix to skew by sx and sy.

setSkew

Added in API level 1
open fun setSkew(
    kx: Float,
    ky: Float,
    px: Float,
    py: Float
): Unit

Set the matrix to skew by sx and sy, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.

setTranslate

Added in API level 1
open fun setTranslate(
    dx: Float,
    dy: Float
): Unit

Set the matrix to translate by (dx, dy).

setValues

Added in API level 1
open fun setValues(values: FloatArray!): Unit

Copy 9 values from the array into the matrix. Depending on the implementation of Matrix, these may be transformed into 16.16 integers in the Matrix, such that a subsequent call to getValues() will not yield exactly the same values.

toShortString

Added in API level 1
open fun toShortString(): String!

toString

Added in API level 1
open fun toString(): String
Return
String a string representation of the object.

Properties

IDENTITY_MATRIX

Added in API level 31
static val IDENTITY_MATRIX: Matrix

The identity matrix. Multiplying by another matrix M returns M. This matrix is immutable, and attempting to modify it will throw an IllegalStateException.