Example usage for android.graphics Matrix MTRANS_X

List of usage examples for android.graphics Matrix MTRANS_X

Introduction

In this page you can find the example usage for android.graphics Matrix MTRANS_X.

Prototype

int MTRANS_X

To view the source code for android.graphics Matrix MTRANS_X.

Click Source Link

Usage

From source file:Main.java

public static void print(Matrix matrix) {
    float scale = getValue(matrix, Matrix.MSCALE_X);

    float moveX = getValue(matrix, Matrix.MTRANS_X);
    float moveY = getValue(matrix, Matrix.MTRANS_Y);

    Log.e("[MatrixUtils]", "matrix: { moveX: " + moveX + ", moveY: " + moveY + ", scale: " + scale + " }");
}

From source file:Main.java

public static Bitmap adjustPhotoRotation(Bitmap bm, final int orientationDegree) {

    Matrix m = new Matrix();
    m.setRotate(orientationDegree, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2);
    float targetX, targetY;
    if (orientationDegree == 90) {
        targetX = bm.getHeight();//from w ww . j  a v  a  2  s  . c o m
        targetY = 0;
    } else {
        targetX = bm.getHeight();
        targetY = bm.getWidth();
    }

    final float[] values = new float[9];
    m.getValues(values);

    float x1 = values[Matrix.MTRANS_X];
    float y1 = values[Matrix.MTRANS_Y];

    m.postTranslate(targetX - x1, targetY - y1);

    Bitmap bm1 = Bitmap.createBitmap(bm.getHeight(), bm.getWidth(), Bitmap.Config.ARGB_8888);
    Paint paint = new Paint();
    Canvas canvas = new Canvas(bm1);
    canvas.drawBitmap(bm, m, paint);

    return bm1;
}

From source file:Main.java

public static Bitmap adjustPhotoRotation(Bitmap bm, final int orientationDegree) {

    Matrix m = new Matrix();
    m.setRotate(orientationDegree, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2);
    float targetX, targetY;
    if (orientationDegree == 90) {
        targetX = bm.getHeight();// w ww.  ja  va  2 s  .c  o m
        targetY = 0;
    } else {
        targetX = bm.getHeight();
        targetY = bm.getWidth();
    }

    final float[] values = new float[9];
    m.getValues(values);

    float x1 = values[Matrix.MTRANS_X];
    float y1 = values[Matrix.MTRANS_Y];

    m.postTranslate(targetX - x1, targetY - y1);

    Bitmap temp = Bitmap.createBitmap(bm.getHeight(), bm.getWidth(), Bitmap.Config.ARGB_8888);

    Paint paint = new Paint();
    Canvas canvas = new Canvas(temp);
    canvas.drawBitmap(bm, m, paint);

    return temp;
}

From source file:Main.java

@SuppressWarnings("unused")
public static void getMatrixTranslation(Matrix matrix, PointF point) {
    synchronized (MATRIX_VALUES) {
        matrix.getValues(MATRIX_VALUES);
        point.x = MATRIX_VALUES[Matrix.MTRANS_X];
        point.y = MATRIX_VALUES[Matrix.MTRANS_Y];
    }//  w w w  . j  a va 2s.c  om
}

From source file:Main.java

public static Drawable rotateBitmap(Bitmap inputBitmap) {
    Matrix matrix = new Matrix();
    matrix.setRotate(90, (float) inputBitmap.getWidth() / 2, (float) inputBitmap.getHeight() / 2);

    float outputX = inputBitmap.getHeight();
    float outputY = 0;

    final float[] values = new float[9];
    matrix.getValues(values);//from w w w  .  ja va  2s  . c o m
    float x1 = values[Matrix.MTRANS_X];
    float y1 = values[Matrix.MTRANS_Y];
    matrix.postTranslate(outputX - x1, outputY - y1);
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap.getHeight(), inputBitmap.getWidth(),
            Bitmap.Config.ARGB_8888);
    Paint paint = new Paint();
    Canvas canvas = new Canvas(outputBitmap);
    canvas.drawBitmap(inputBitmap, matrix, paint);
    return new BitmapDrawable(null, outputBitmap);
}

From source file:Main.java

public static Bitmap adjustPhotoRotation(Bitmap bm, final int orientationDegree) {
    Matrix m = new Matrix();
    m.setRotate(orientationDegree, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2);
    float targetX, targetY;
    if (orientationDegree == 90) {
        targetX = bm.getHeight();/*from w ww  .j ava 2s.  c o  m*/
        targetY = 0;
    } else {
        targetX = bm.getHeight();
        targetY = bm.getWidth();
    }
    final float[] values = new float[9];
    m.getValues(values);
    float x1 = values[Matrix.MTRANS_X];
    float y1 = values[Matrix.MTRANS_Y];
    m.postTranslate(targetX - x1, targetY - y1);
    Bitmap bm1 = Bitmap.createBitmap(bm.getHeight(), bm.getWidth(), Bitmap.Config.ARGB_8888);
    Paint paint = new Paint();
    Canvas canvas = new Canvas(bm1);
    canvas.drawBitmap(bm, m, paint);
    bm.recycle();
    bm = null;
    return bm1;
}

From source file:com.example.PagerCoverFlow.PagerContainer.java

private void transformImageBitmap(ImageView child, Matrix imageMatrix, int rotationAngle) {
    mCamera.save();/*from  w ww  . j a  v  a  2  s  .  com*/
    //        final Matrix imageMatrix = t.getMatrix();;
    final int imageHeight = child.getLayoutParams().height;
    final int imageWidth = child.getLayoutParams().width;
    final int rotation = Math.abs(rotationAngle);

    //      mCamera.translate(0.0f, 0.0f, 100.0f);
    Log.i("Select", "imageWidth:" + imageWidth + " " + "imageHeight:" + imageHeight);
    //As the angle of the view gets less, zoom in
    //      if ( rotation < mMaxRotationAngle )
    {
        float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));
        Log.i("Select", "rotation:" + rotation + " zoomAmount:" + zoomAmount);
        mCamera.translate(0.0f, 0.0f, zoomAmount);
    }

    //Alpha
    int alphaVal = 255 - rotation * 3;
    //      child.setAlpha(alphaVal); //[0,255]
    child.getDrawable().setAlpha(alphaVal);
    //      mCamera.rotateY(rotationAngle);
    mCamera.getMatrix(imageMatrix);
    imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
    imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));
    mCamera.restore();

    float[] values = new float[9];
    imageMatrix.getValues(values);
    float globalX = values[Matrix.MTRANS_X];
    float globalY = values[Matrix.MTRANS_Y];
    //      float width = values[Matrix.MSCALE_X]*CommonValue.menuWidth ;
    //      float height = values[Matrix.MSCALE_Y]*CommonValue.menuWidth;
    values[Matrix.MSCALE_X] = 2;
    values[Matrix.MSCALE_Y] = 2;
    imageMatrix.setValues(values);
}

From source file:org.witness.informacam.app.editors.image.ImageRegion.java

public void updateMatrix() {
    float[] mValues = new float[9];
    mMatrix.getValues(mValues);//from   ww  w  . java2 s.  c om
    mMatrix.invert(iMatrix);
    scaleX = mValues[Matrix.MSCALE_X];
    scaleY = mValues[Matrix.MSCALE_Y];

    leftOffset = mValues[Matrix.MTRANS_X];
    topOffset = mValues[Matrix.MTRANS_Y];

}

From source file:com.jsibbold.zoomage.ZoomageView.java

/**
 * Update the bounds of the displayed image based on the current matrix.
 *
 * @param values the image's current matrix values.
 *///from   www  .j  ava 2  s .co m
private void updateBounds(final float[] values) {
    if (getDrawable() != null) {
        bounds.set(values[Matrix.MTRANS_X], values[Matrix.MTRANS_Y],
                getDrawable().getIntrinsicWidth() * values[Matrix.MSCALE_X] + values[Matrix.MTRANS_X],
                getDrawable().getIntrinsicHeight() * values[Matrix.MSCALE_Y] + values[Matrix.MTRANS_Y]);
    }
}

From source file:android.support.transition.ChangeTransform.java

private ObjectAnimator createTransformAnimator(TransitionValues startValues, TransitionValues endValues,
        final boolean handleParentChange) {
    Matrix startMatrix = (Matrix) startValues.values.get(PROPNAME_MATRIX);
    Matrix endMatrix = (Matrix) endValues.values.get(PROPNAME_MATRIX);

    if (startMatrix == null) {
        startMatrix = MatrixUtils.IDENTITY_MATRIX;
    }//from w  w  w . j av  a2  s.c o  m

    if (endMatrix == null) {
        endMatrix = MatrixUtils.IDENTITY_MATRIX;
    }

    if (startMatrix.equals(endMatrix)) {
        return null;
    }

    final Transforms transforms = (Transforms) endValues.values.get(PROPNAME_TRANSFORMS);

    // clear the transform properties so that we can use the animation matrix instead
    final View view = endValues.view;
    setIdentityTransforms(view);

    final float[] startMatrixValues = new float[9];
    startMatrix.getValues(startMatrixValues);
    final float[] endMatrixValues = new float[9];
    endMatrix.getValues(endMatrixValues);
    final PathAnimatorMatrix pathAnimatorMatrix = new PathAnimatorMatrix(view, startMatrixValues);

    PropertyValuesHolder valuesProperty = PropertyValuesHolder.ofObject(NON_TRANSLATIONS_PROPERTY,
            new FloatArrayEvaluator(new float[9]), startMatrixValues, endMatrixValues);
    Path path = getPathMotion().getPath(startMatrixValues[Matrix.MTRANS_X], startMatrixValues[Matrix.MTRANS_Y],
            endMatrixValues[Matrix.MTRANS_X], endMatrixValues[Matrix.MTRANS_Y]);
    PropertyValuesHolder translationProperty = PropertyValuesHolderUtils.ofPointF(TRANSLATIONS_PROPERTY, path);
    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(pathAnimatorMatrix, valuesProperty,
            translationProperty);

    final Matrix finalEndMatrix = endMatrix;

    AnimatorListenerAdapter listener = new AnimatorListenerAdapter() {
        private boolean mIsCanceled;
        private Matrix mTempMatrix = new Matrix();

        @Override
        public void onAnimationCancel(Animator animation) {
            mIsCanceled = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (!mIsCanceled) {
                if (handleParentChange && mUseOverlay) {
                    setCurrentMatrix(finalEndMatrix);
                } else {
                    view.setTag(R.id.transition_transform, null);
                    view.setTag(R.id.parent_matrix, null);
                }
            }
            ViewUtils.setAnimationMatrix(view, null);
            transforms.restore(view);
        }

        @Override
        public void onAnimationPause(Animator animation) {
            Matrix currentMatrix = pathAnimatorMatrix.getMatrix();
            setCurrentMatrix(currentMatrix);
        }

        @Override
        public void onAnimationResume(Animator animation) {
            setIdentityTransforms(view);
        }

        private void setCurrentMatrix(Matrix currentMatrix) {
            mTempMatrix.set(currentMatrix);
            view.setTag(R.id.transition_transform, mTempMatrix);
            transforms.restore(view);
        }
    };

    animator.addListener(listener);
    AnimatorUtils.addPauseListener(animator, listener);
    return animator;
}