Code example for Matrix

Methods: getValues, postScale, postTranslate

0
        cutting(); 
        return super.setFrame(l, t, r, b);
    } 
 
    protected float getValue(Matrix matrix, int whichValue) {
        matrix.getValues(mMatrixValues);
        return mMatrixValues[whichValue];
    } 
 
    protected float getScale() { 
        return getValue(mMatrix, Matrix.MSCALE_X);
    } 
 
    public float getTranslateX() { 
        return getValue(mMatrix, Matrix.MTRANS_X);
    } 
 
    protected float getTranslateY() { 
        return getValue(mMatrix, Matrix.MTRANS_Y);
    } 
 
    protected void maxZoomTo(int x, int y) {
        if (mMinScale != getScale() && (getScale() - mMinScale) > 0.1f) {
            // threshold 0.1f 
            float scale = mMinScale / getScale();
            zoomTo(scale, x, y);
        } else { 
            float scale = MAX_SCALE / getScale();
            zoomTo(scale, x, y);
        } 
    } 
 
    public void zoomTo(float scale, int x, int y) {
        if (getScale() * scale < mMinScale) {
            return; 
        } 
        if (scale >= 1 && getScale() * scale > MAX_SCALE) {
            return; 
        } 
        mMatrix.postScale(scale, scale);
        // move to center 
        mMatrix.postTranslate(-(mWidth * scale - mWidth) / 2, -(mHeight * scale - mHeight) / 2);
 
        // move x and y distance 
        mMatrix.postTranslate(-(x - (mWidth / 2)) * scale, 0);
        mMatrix.postTranslate(0, -(y - (mHeight / 2)) * scale);
        setImageMatrix(mMatrix);
    } 
 
    public void cutting() { 
        int width = (int) (mIntrinsicWidth * getScale());