Android image transformation matrix stuff.
**Useful image transformation matrix **
Source: Math StackExchange
/**
* <pre>
* Calculate the difference between the old transformation matrix and the new matrix, based on the following formula:
* Difference = (O) * (N^-1)
* O: old transformation matrix.
* N: new matrix.
* Source: https://math.stackexchange.com/q/1399401
* Position is very important in matrix operation.
*
* This one has been tested with rotate, scale, translation.
* </pre>
*
* @param oldMatrix the matrix to calculate the difference from
* @param newMatrix the new input matrix.
* @return a matrix that represent the difference from the old matrix.
*/
public static Matrix getDifferenceMatrix(Matrix oldMatrix, Matrix newMatrix){
Matrix diffMatrix = new Matrix();
newMatrix.invert(diffMatrix);
diffMatrix.postConcat(oldMatrix);
diffMatrix.invert(diffMatrix);
return diffMatrix;
}
Source: StackOverFlow
Rect
in android doesn't rotate. After we rotate an image it will only result in a new Rect
that can fit all those new corners.Matrix m = new Matrix();
RectF drawableRect = new RectF(0, 0, imageWidth, imageHeight);
RectF viewRect = new RectF(0, 0, imageView.getWidth(), imageView.getHeight());
m.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER);
imageView.setImageMatrix(m);