remove Matrix Scale - Android java.lang

Android examples for java.lang:Math Matrix

Description

remove Matrix Scale

Demo Code


//package com.java2s;
import android.graphics.Matrix;

public class Main {
    public static Matrix removeScale(Matrix matrix) {
        Matrix newMatrix = new Matrix();
        float[] v = new float[9];
        matrix.getValues(v);//from  w w  w. j  a v  a 2s .c  om
        // translation is simple
        float tx = v[Matrix.MTRANS_X];
        float ty = v[Matrix.MTRANS_Y];
        newMatrix.postTranslate(tx, ty);
        // calculate real scale
        float scalex = v[Matrix.MSCALE_X];
        float skewy = v[Matrix.MSKEW_Y];
        float rScale = (float) Math.sqrt(scalex * scalex + skewy * skewy);
        // calculate the degree of rotation
        float rAngle = -Math.round(Math.atan2(v[Matrix.MSKEW_X],
                v[Matrix.MSCALE_X]) * (180 / Math.PI));
        newMatrix.postRotate(rAngle);
        return newMatrix;
    }
}

Related Tutorials