List of usage examples for android.graphics Matrix MSKEW_X
int MSKEW_X
To view the source code for android.graphics Matrix MSKEW_X.
Click Source Link
From source file:Main.java
@SuppressWarnings("unused") public static int getMatrixRotateDegrees(Matrix matrix) { synchronized (MATRIX_VALUES) { matrix.getValues(MATRIX_VALUES); final float skewX = MATRIX_VALUES[Matrix.MSKEW_X]; final float scaleX = MATRIX_VALUES[Matrix.MSCALE_X]; //noinspection SuspiciousNameCombination final int degrees = (int) Math.round(Math.atan2(skewX, scaleX) * (180 / Math.PI)); if (degrees < 0) { return Math.abs(degrees); } else if (degrees > 0) { return 360 - degrees; } else {//from w w w .j a va 2s. c o m return 0; } } }
From source file:android.support.graphics.drawable.VectorDrawableCompat.java
@Override public void draw(Canvas canvas) { if (mDelegateDrawable != null) { mDelegateDrawable.draw(canvas);//from w w w . ja va2 s . com 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:it.mb.whatshare.Utils.java
/** * Applies the transformations stored in the array of float values to the * argument list of points./*from ww w.j ava 2 s. com*/ * * <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; } }