List of usage examples for android.graphics Matrix preTranslate
public boolean preTranslate(float dx, float dy)
From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java
private void drawHighresImage(Canvas canvas, Bitmap fullHighres) { Matrix originalToScreen = MasterImage.getImage().originalImageToScreen(); if (fullHighres != null && originalToScreen != null) { Matrix screenToOriginal = new Matrix(); originalToScreen.invert(screenToOriginal); Rect rBounds = new Rect(); rBounds.set(MasterImage.getImage().getPartialBounds()); if (fullHighres != null) { originalToScreen.preTranslate(rBounds.left, rBounds.top); canvas.clipRect(mImageBounds); canvas.drawBitmap(fullHighres, originalToScreen, mPaint); }/* w ww . j a va2 s .co m*/ } }
From source file:com.ferdi2005.secondgram.AndroidUtilities.java
public static void setRectToRect(Matrix matrix, RectF src, RectF dst, int rotation, Matrix.ScaleToFit align) { float tx, sx; float ty, sy; if (rotation == 90 || rotation == 270) { sx = dst.height() / src.width(); sy = dst.width() / src.height(); } else {/*from www .j a v a2 s . c o m*/ sx = dst.width() / src.width(); sy = dst.height() / src.height(); } if (align != Matrix.ScaleToFit.FILL) { if (sx > sy) { sx = sy; } else { sy = sx; } } tx = -src.left * sx; ty = -src.top * sy; matrix.setTranslate(dst.left, dst.top); if (rotation == 90) { matrix.preRotate(90); matrix.preTranslate(0, -dst.width()); } else if (rotation == 180) { matrix.preRotate(180); matrix.preTranslate(-dst.width(), -dst.height()); } else if (rotation == 270) { matrix.preRotate(270); matrix.preTranslate(-dst.height(), 0); } matrix.preScale(sx, sy); matrix.preTranslate(tx, ty); }
From source file:com.jiahuan.svgmapview.core.helper.map.SVGParser.java
private static Matrix parseTransformItem(String s, Matrix matrix) { if (s.startsWith("matrix(")) { NumberParse np = parseNumbers(s.substring("matrix(".length())); if (np.numbers.size() == 6) { Matrix mat = new Matrix(); mat.setValues(new float[] { // Row 1 np.numbers.get(0), np.numbers.get(2), np.numbers.get(4), // Row 2 np.numbers.get(1), np.numbers.get(3), np.numbers.get(5), // Row 3 0, 0, 1, });// ww w . j a v a2s.c o m matrix.preConcat(mat); } } else if (s.startsWith("translate(")) { NumberParse np = parseNumbers(s.substring("translate(".length())); if (np.numbers.size() > 0) { float tx = np.numbers.get(0); float ty = 0; if (np.numbers.size() > 1) { ty = np.numbers.get(1); } matrix.preTranslate(tx, ty); } } else if (s.startsWith("scale(")) { NumberParse np = parseNumbers(s.substring("scale(".length())); if (np.numbers.size() > 0) { float sx = np.numbers.get(0); float sy = sx; if (np.numbers.size() > 1) { sy = np.numbers.get(1); } matrix.preScale(sx, sy); } } else if (s.startsWith("skewX(")) { NumberParse np = parseNumbers(s.substring("skewX(".length())); if (np.numbers.size() > 0) { float angle = np.numbers.get(0); matrix.preSkew((float) Math.tan(angle), 0); } } else if (s.startsWith("skewY(")) { NumberParse np = parseNumbers(s.substring("skewY(".length())); if (np.numbers.size() > 0) { float angle = np.numbers.get(0); matrix.preSkew(0, (float) Math.tan(angle)); } } else if (s.startsWith("rotate(")) { NumberParse np = parseNumbers(s.substring("rotate(".length())); if (np.numbers.size() > 0) { float angle = np.numbers.get(0); float cx = 0; float cy = 0; if (np.numbers.size() > 2) { cx = np.numbers.get(1); cy = np.numbers.get(2); } matrix.preTranslate(-cx, -cy); matrix.preRotate(angle); matrix.preTranslate(cx, cy); } } else { Log.w(TAG, "Invalid transform (" + s + ")"); } return matrix; }
From source file:im.ene.lab.design.widget.coverflow.FeatureCoverFlow.java
private void setChildTransformation(View child, Matrix m) { m.reset();//www. j ava 2 s.c o m // TODO FIXME // addChildRotation(child, m); addChildScale(child, m); addChildCircularPathZOffset(child, m); addChildAdjustPosition(child, m); //set coordinate system origin to center of child m.preTranslate(-child.getWidth() / 2f, -child.getHeight() / 2f); //move back m.postTranslate(child.getWidth() / 2f, child.getHeight() / 2f); }
From source file:com.larvalabs.svgandroid.SVGParser.java
private static Matrix parseTransformItem(String s, Matrix matrix) { if (s.startsWith("matrix(")) { NumberParse np = parseNumbers(s.substring("matrix(".length())); if (np.numbers.size() == 6) { Matrix mat = new Matrix(); mat.setValues(new float[] { // Row 1 np.numbers.get(0), np.numbers.get(2), np.numbers.get(4), // Row 2 np.numbers.get(1), np.numbers.get(3), np.numbers.get(5), // Row 3 0, 0, 1, });/*from w ww.j a va2s . com*/ matrix.preConcat(mat); } } else if (s.startsWith("translate(")) { NumberParse np = parseNumbers(s.substring("translate(".length())); if (np.numbers.size() > 0) { float tx = np.numbers.get(0); float ty = 0; if (np.numbers.size() > 1) { ty = np.numbers.get(1); } matrix.preTranslate(tx, ty); } } else if (s.startsWith("scale(")) { NumberParse np = parseNumbers(s.substring("scale(".length())); if (np.numbers.size() > 0) { float sx = np.numbers.get(0); float sy = sx; if (np.numbers.size() > 1) { sy = np.numbers.get(1); } matrix.preScale(sx, sy); } } else if (s.startsWith("skewX(")) { NumberParse np = parseNumbers(s.substring("skewX(".length())); if (np.numbers.size() > 0) { float angle = np.numbers.get(0); matrix.preSkew((float) Math.tan(angle), 0); } } else if (s.startsWith("skewY(")) { NumberParse np = parseNumbers(s.substring("skewY(".length())); if (np.numbers.size() > 0) { float angle = np.numbers.get(0); matrix.preSkew(0, (float) Math.tan(angle)); } } else if (s.startsWith("rotate(")) { NumberParse np = parseNumbers(s.substring("rotate(".length())); if (np.numbers.size() > 0) { float angle = np.numbers.get(0); float cx = 0; float cy = 0; if (np.numbers.size() > 2) { cx = np.numbers.get(1); cy = np.numbers.get(2); } matrix.preTranslate(cx, cy); matrix.preRotate(angle); matrix.preTranslate(-cx, -cy); } } else { Log.i(TAG, "Invalid transform (" + s + ")"); } return matrix; }
From source file:android.support.v17.leanback.app.BackgroundManager.java
/** * Sets the given bitmap into the background. When using setBitmap to set the * background, the provided bitmap will be scaled and cropped to correctly * fit within the dimensions of the view. The timing for when this becomes * visible in the app is undefined and may take place after a small delay. *//*w ww . ja v a2 s .c o m*/ public void setBitmap(Bitmap bitmap) { if (DEBUG) { Log.v(TAG, "setBitmap " + bitmap); } if (bitmap == null) { setDrawableInternal(null); return; } if (bitmap.getWidth() <= 0 || bitmap.getHeight() <= 0) { if (DEBUG) { Log.v(TAG, "invalid bitmap width or height"); } return; } Matrix matrix = null; if ((bitmap.getWidth() != mWidthPx || bitmap.getHeight() != mHeightPx)) { int dwidth = bitmap.getWidth(); int dheight = bitmap.getHeight(); float scale; // Scale proportionately to fit width and height. if (dwidth * mHeightPx > mWidthPx * dheight) { scale = (float) mHeightPx / (float) dheight; } else { scale = (float) mWidthPx / (float) dwidth; } int subX = Math.min((int) (mWidthPx / scale), dwidth); int dx = Math.max(0, (dwidth - subX) / 2); matrix = new Matrix(); matrix.setScale(scale, scale); matrix.preTranslate(-dx, 0); if (DEBUG) Log.v(TAG, "original image size " + bitmap.getWidth() + "x" + bitmap.getHeight() + " scale " + scale + " dx " + dx); } BitmapDrawable bitmapDrawable = new BitmapDrawable(mContext.getResources(), bitmap, matrix); setDrawableInternal(bitmapDrawable); }