Example usage for android.graphics Matrix MSCALE_Y

List of usage examples for android.graphics Matrix MSCALE_Y

Introduction

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

Prototype

int MSCALE_Y

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

Click Source Link

Usage

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

private void transformImageBitmap(ImageView child, Matrix imageMatrix, int rotationAngle) {
    mCamera.save();//from   w  w w  . j av  a2s  .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:android.support.graphics.drawable.VectorDrawableCompat.java

@Override
public void draw(Canvas canvas) {
    if (mDelegateDrawable != null) {
        mDelegateDrawable.draw(canvas);//w  w  w. j a v a2s.c  o  m
        return;
    }
    // We will offset the bounds for drawBitmap, so copyBounds() here instead
    // of getBounds().
    copyBounds(mTmpBounds);
    if (mTmpBounds.width() <= 0 || mTmpBounds.height() <= 0) {
        // Nothing to draw
        return;
    }

    // Color filters always override tint filters.
    final ColorFilter colorFilter = (mColorFilter == null ? mTintFilter : mColorFilter);

    // The imageView can scale the canvas in different ways, in order to
    // avoid blurry scaling, we have to draw into a bitmap with exact pixel
    // size first. This bitmap size is determined by the bounds and the
    // canvas scale.
    canvas.getMatrix(mTmpMatrix);
    mTmpMatrix.getValues(mTmpFloats);
    float canvasScaleX = Math.abs(mTmpFloats[Matrix.MSCALE_X]);
    float canvasScaleY = Math.abs(mTmpFloats[Matrix.MSCALE_Y]);

    float canvasSkewX = Math.abs(mTmpFloats[Matrix.MSKEW_X]);
    float canvasSkewY = Math.abs(mTmpFloats[Matrix.MSKEW_Y]);

    // When there is any rotation / skew, then the scale value is not valid.
    if (canvasSkewX != 0 || canvasSkewY != 0) {
        canvasScaleX = 1.0f;
        canvasScaleY = 1.0f;
    }

    int scaledWidth = (int) (mTmpBounds.width() * canvasScaleX);
    int scaledHeight = (int) (mTmpBounds.height() * canvasScaleY);
    scaledWidth = Math.min(MAX_CACHED_BITMAP_SIZE, scaledWidth);
    scaledHeight = Math.min(MAX_CACHED_BITMAP_SIZE, scaledHeight);

    if (scaledWidth <= 0 || scaledHeight <= 0) {
        return;
    }

    final int saveCount = canvas.save();
    canvas.translate(mTmpBounds.left, mTmpBounds.top);

    // Handle RTL mirroring.
    final boolean needMirroring = needMirroring();
    if (needMirroring) {
        canvas.translate(mTmpBounds.width(), 0);
        canvas.scale(-1.0f, 1.0f);
    }

    // At this point, canvas has been translated to the right position.
    // And we use this bound for the destination rect for the drawBitmap, so
    // we offset to (0, 0);
    mTmpBounds.offsetTo(0, 0);

    mVectorState.createCachedBitmapIfNeeded(scaledWidth, scaledHeight);
    if (!mAllowCaching) {
        mVectorState.updateCachedBitmap(scaledWidth, scaledHeight);
    } else {
        if (!mVectorState.canReuseCache()) {
            mVectorState.updateCachedBitmap(scaledWidth, scaledHeight);
            mVectorState.updateCacheStates();
        }
    }
    mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter, mTmpBounds);
    canvas.restoreToCount(saveCount);
}

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

public void updateMatrix() {
    float[] mValues = new float[9];
    mMatrix.getValues(mValues);/*from   w  w w .  j  a  v a2 s . c o m*/
    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   w  w w.j a  v a2s  .  c o 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:com.jsibbold.zoomage.ZoomageView.java

/**
 * Get the height of the displayed image.
 *
 * @return the current height of the image as displayed (not the height of the {@link ImageView} itself.
 *///from   w  w  w . j av  a2  s .  c  om
private float getCurrentDisplayedHeight() {
    if (getDrawable() != null)
        return getDrawable().getIntrinsicHeight() * mValues[Matrix.MSCALE_Y];
    else
        return 0;
}

From source file:com.hippo.vector.VectorDrawable.java

@Override
@SuppressWarnings("deprecation")
public void draw(Canvas canvas) {
    // We will offset the bounds for drawBitmap, so copyBounds() here instead
    // of getBounds().
    copyBounds(mTmpBounds);/*from  w w w . j  av  a  2  s.  c o  m*/
    if (mTmpBounds.width() <= 0 || mTmpBounds.height() <= 0) {
        // Nothing to draw
        return;
    }

    // Color filters always override tint filters.
    final ColorFilter colorFilter = (mColorFilter == null ? mTintFilter : mColorFilter);

    // The imageView can scale the canvas in different ways, in order to
    // avoid blurry scaling, we have to draw into a bitmap with exact pixel
    // size first. This bitmap size is determined by the bounds and the
    // canvas scale.
    canvas.getMatrix(mTmpMatrix);
    mTmpMatrix.getValues(mTmpFloats);
    float canvasScaleX = Math.abs(mTmpFloats[Matrix.MSCALE_X]);
    float canvasScaleY = Math.abs(mTmpFloats[Matrix.MSCALE_Y]);
    int scaledWidth = (int) (mTmpBounds.width() * canvasScaleX);
    int scaledHeight = (int) (mTmpBounds.height() * canvasScaleY);
    scaledWidth = Math.min(MAX_CACHED_BITMAP_SIZE, scaledWidth);
    scaledHeight = Math.min(MAX_CACHED_BITMAP_SIZE, scaledHeight);

    if (scaledWidth <= 0 || scaledHeight <= 0) {
        return;
    }

    final int saveCount = canvas.save();
    canvas.translate(mTmpBounds.left, mTmpBounds.top);

    // Handle RTL mirroring.
    final boolean needMirroring = needMirroring();
    if (needMirroring) {
        canvas.translate(mTmpBounds.width(), 0);
        canvas.scale(-1.0f, 1.0f);
    }

    // At this point, canvas has been translated to the right position.
    // And we use this bound for the destination rect for the drawBitmap, so
    // we offset to (0, 0);
    mTmpBounds.offsetTo(0, 0);

    mVectorState.createCachedBitmapIfNeeded(scaledWidth, scaledHeight);
    if (!mAllowCaching) {
        mVectorState.updateCachedBitmap(scaledWidth, scaledHeight);
    } else {
        if (!mVectorState.canReuseCache()) {
            mVectorState.updateCachedBitmap(scaledWidth, scaledHeight);
            mVectorState.updateCacheStates();
        }
    }
    mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter, mTmpBounds);
    canvas.restoreToCount(saveCount);
}

From source file:com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.java

@Override
public void draw(Canvas canvas) {
    // We will offset the bounds for drawBitmap, so copyBounds() here instead
    // of getBounds().
    copyBounds(mTmpBounds);/*from ww  w.  java 2  s. c o  m*/
    if (mTmpBounds.width() <= 0 || mTmpBounds.height() <= 0) {
        // Nothing to draw
        return;
    }
    // Color filters always override tint filters.
    final ColorFilter colorFilter = (mColorFilter == null ? mTintFilter : mColorFilter);
    // The imageView can scale the canvas in different ways, in order to
    // avoid blurry scaling, we have to draw into a bitmap with exact pixel
    // size first. This bitmap size is determined by the bounds and the
    // canvas scale.
    canvas.getMatrix(mTmpMatrix);
    mTmpMatrix.getValues(mTmpFloats);
    float canvasScaleX = Math.abs(mTmpFloats[Matrix.MSCALE_X]);
    float canvasScaleY = Math.abs(mTmpFloats[Matrix.MSCALE_Y]);
    int scaledWidth = (int) (mTmpBounds.width() * canvasScaleX);
    int scaledHeight = (int) (mTmpBounds.height() * canvasScaleY);
    scaledWidth = Math.min(MAX_CACHED_BITMAP_SIZE, scaledWidth);
    scaledHeight = Math.min(MAX_CACHED_BITMAP_SIZE, scaledHeight);
    if (scaledWidth <= 0 || scaledHeight <= 0) {
        return;
    }
    final int saveCount = canvas.save();
    canvas.translate(mTmpBounds.left, mTmpBounds.top);
    // Handle RTL mirroring.
    final boolean needMirroring = needMirroring();
    if (needMirroring) {
        canvas.translate(mTmpBounds.width(), 0);
        canvas.scale(-1.0f, 1.0f);
    }
    // At this point, canvas has been translated to the right position.
    // And we use this bound for the destination rect for the drawBitmap, so
    // we offset to (0, 0);
    mTmpBounds.offsetTo(0, 0);
    mVectorState.createCachedBitmapIfNeeded(scaledWidth, scaledHeight);
    if (!mAllowCaching) {
        mVectorState.updateCachedBitmap(scaledWidth, scaledHeight);
    } else {
        if (!mVectorState.canReuseCache()) {
            mVectorState.updateCachedBitmap(scaledWidth, scaledHeight);
            mVectorState.updateCacheStates();
        }
    }
    mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter, mTmpBounds);
    canvas.restoreToCount(saveCount);
}

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

/**
 * Animate the matrix back to its original position after the user stopped interacting with it.
 *//*from   w ww. j a  v a2s. co  m*/
private void animateToStartMatrix() {

    final Matrix beginMatrix = new Matrix(getImageMatrix());
    beginMatrix.getValues(mValues);

    //difference in current and original values
    final float xsdiff = startValues[Matrix.MSCALE_X] - mValues[Matrix.MSCALE_X];
    final float ysdiff = startValues[Matrix.MSCALE_Y] - mValues[Matrix.MSCALE_Y];
    final float xtdiff = startValues[Matrix.MTRANS_X] - mValues[Matrix.MTRANS_X];
    final float ytdiff = startValues[Matrix.MTRANS_Y] - mValues[Matrix.MTRANS_Y];

    ValueAnimator anim = ValueAnimator.ofFloat(0, 1f);
    anim.addUpdateListener(new AnimatorUpdateListener() {

        final Matrix activeMatrix = new Matrix(getImageMatrix());
        final float[] values = new float[9];

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float val = (Float) animation.getAnimatedValue();
            activeMatrix.set(beginMatrix);
            activeMatrix.getValues(values);
            values[Matrix.MTRANS_X] = values[Matrix.MTRANS_X] + xtdiff * val;
            values[Matrix.MTRANS_Y] = values[Matrix.MTRANS_Y] + ytdiff * val;
            values[Matrix.MSCALE_X] = values[Matrix.MSCALE_X] + xsdiff * val;
            values[Matrix.MSCALE_Y] = values[Matrix.MSCALE_Y] + ysdiff * val;
            activeMatrix.setValues(values);
            setImageMatrix(activeMatrix);
        }
    });
    anim.setDuration(RESET_DURATION);
    anim.start();
}

From source file:it.mb.whatshare.Utils.java

/**
 * Applies the transformations stored in the array of float values to the
 * argument list of points./*  ww  w . ja  va  2  s. co  m*/
 * 
 * <p>
 * The float array can be obtained starting from a {@link Matrix} object by
 * calling <blockquote>
 * 
 * <pre>
 * Matrix myMatrix;
 * float[] matrixValues = new float[9];
 * myMatrix.getValues(matrixValues);
 * </pre>
 * 
 * </blockquote>
 * 
 * @param matrixValues
 *            the values to apply to all points in the list
 * @param points
 *            a list of points to which the transformations in the array
 *            will be applied
 */
public static void applyMatrix(float[] matrixValues, List<PointF> points) {
    // variable names are the same used by Skia library
    final float tx = matrixValues[Matrix.MTRANS_X];
    final float ty = matrixValues[Matrix.MTRANS_Y];
    final float mx = matrixValues[Matrix.MSCALE_X];
    final float my = matrixValues[Matrix.MSCALE_Y];
    final float kx = matrixValues[Matrix.MSKEW_X];
    final float ky = matrixValues[Matrix.MSKEW_Y];
    /*
     * if rotation: skia messes up with the matrix, so sx and sy actually
     * store cosV, rx and ry store -sinV and sinV
     */
    for (PointF point : points) {
        final float originalY = point.y;
        point.y = point.x * ky + (point.y * my) + ty;
        point.x = point.x * mx + (originalY * kx) + tx;
    }
}

From source file:com.goka.flickableview.ImageViewTouchBase.java

public void printMatrix(Matrix matrix) {
    float scaleX = getValue(matrix, Matrix.MSCALE_X);
    float scaleY = getValue(matrix, Matrix.MSCALE_Y);
    float tx = getValue(matrix, Matrix.MTRANS_X);
    float ty = getValue(matrix, Matrix.MTRANS_Y);
    LogUtil.D(TAG, "matrix: { x: " + tx + ", y: " + ty + ", scaleX: " + scaleX + ", scaleY: " + scaleY + " }");
}