/** * Sets the scale factor to the specified values. x and y is pivot. * * @param scaleX * @param scaleY * @param x * @param y * @return */ public Matrix setZoom(float scaleX, float scaleY, float x, float y) { Matrix save = new Matrix(); save.set(mMatrixTouch); save.setScale(scaleX, scaleY, x, y); return save; }
/** * Post-scales by the specified scale factors. * * @param scaleX * @param scaleY * @return */ public Matrix zoom(float scaleX, float scaleY) { Matrix save = new Matrix(); zoom(scaleX, scaleY, save); return save; }
/** * Zooms out by 0.7f, x and y are the coordinates (in pixels) of the zoom * center. */ public Matrix zoomOut(float x, float y) { Matrix save = new Matrix(); zoomOut(x, y, save); return save; }
/** * Sets the scale factor to the specified values. * * @param scaleX * @param scaleY * @return */ public Matrix setZoom(float scaleX, float scaleY) { Matrix save = new Matrix(); setZoom(scaleX, scaleY, save); return save; }
/** * Resets all zooming and dragging and makes the chart fit exactly it's * bounds. */ public Matrix fitScreen() { Matrix save = new Matrix(); fitScreen(save); return save; }
/** * Post-translates to the specified points. Less Performant. * * @param transformedPts * @return */ public Matrix translate(final float[] transformedPts) { Matrix save = new Matrix(); translate(transformedPts, save); return save; }
/** * Zooms in by 1.4f, x and y are the coordinates (in pixels) of the zoom * center. * * @param x * @param y */ public Matrix zoomIn(float x, float y) { Matrix save = new Matrix(); zoomIn(x, y, save); return save; }
private Bitmap rotatingImage(Bitmap bitmap, int angle) { Matrix matrix = new Matrix(); matrix.postRotate(angle); return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); }
/** * Post-scales by the specified scale factors. x and y is pivot. * * @param scaleX * @param scaleY * @param x * @param y * @return */ public Matrix zoom(float scaleX, float scaleY, float x, float y) { Matrix save = new Matrix(); zoom(scaleX, scaleY, x, y, save); return save; }
FixedSizeDrawable(State state, Drawable wrapped) { this.state = Preconditions.checkNotNull(state); this.wrapped = Preconditions.checkNotNull(wrapped); // We will do our own scaling. wrapped.setBounds(0, 0, wrapped.getIntrinsicWidth(), wrapped.getIntrinsicHeight()); matrix = new Matrix(); wrappedRect = new RectF(0, 0, wrapped.getIntrinsicWidth(), wrapped.getIntrinsicHeight()); bounds = new RectF(); }
@Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); mRect.set(0, 0, bounds.width(), bounds.height()); radius = Math.min(bounds.width(), bounds.height()) / 2; strokeRadius = radius - strokeWidth / 2; // Resize the original bitmap to fit the new bound Matrix shaderMatrix = new Matrix(); shaderMatrix.setRectToRect(mBitmapRect, mRect, Matrix.ScaleToFit.FILL); bitmapShader.setLocalMatrix(shaderMatrix); }
@Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); mRect.set(margin, margin, bounds.width() - margin, bounds.height() - margin); // Resize the original bitmap to fit the new bound Matrix shaderMatrix = new Matrix(); shaderMatrix.setRectToRect(mBitmapRect, mRect, Matrix.ScaleToFit.FILL); bitmapShader.setLocalMatrix(shaderMatrix); }
@Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); RadialGradient vignette = new RadialGradient( mRect.centerX(), mRect.centerY() * 1.0f / 0.7f, mRect.centerX() * 1.3f, new int[]{0, 0, 0x7f000000}, new float[]{0.0f, 0.7f, 1.0f}, Shader.TileMode.CLAMP); Matrix oval = new Matrix(); oval.setScale(1.0f, 0.7f); vignette.setLocalMatrix(oval); paint.setShader(new ComposeShader(bitmapShader, vignette, PorterDuff.Mode.SRC_OVER)); } }
@Test public void visualize_shouldReturnDescription() throws Exception { Canvas canvas = new Canvas(targetBitmap); canvas.drawBitmap(imageBitmap, new Matrix(), new Paint()); canvas.drawBitmap(imageBitmap, new Matrix(), new Paint()); assertEquals("Bitmap for file:/an/image.jpg transformed by Matrix[pre=[], set={}, post=[]]\n" + "Bitmap for file:/an/image.jpg transformed by Matrix[pre=[], set={}, post=[]]", ShadowCanvas.visualize(canvas)); }
@Test public void testPostTranslate() { final Matrix matrix1 = new Matrix(); matrix1.postTranslate(1.0f, 1.0f); assertPointsEqual(mapPoint(matrix1, 1.0f, 1.0f), new PointF(2.0f, 2.0f)); matrix1.postTranslate(2.0f, 2.0f); assertPointsEqual(mapPoint(matrix1, 1.0f, 1.0f), new PointF(4.0f, 4.0f)); final Matrix matrix2 = new Matrix(); matrix2.setScale(2.0f, 2.0f); matrix2.postTranslate(-5.0f, 10.0f); assertPointsEqual(mapPoint(matrix2, 1.0f, 1.0f), new PointF(-3.0f, 12.0f)); }
@Test public void shouldDescribeBitmapDrawing_WithMatrix() throws Exception { Canvas canvas = new Canvas(targetBitmap); canvas.drawBitmap(imageBitmap, new Matrix(), new Paint()); canvas.drawBitmap(imageBitmap, new Matrix(), new Paint()); assertEquals("Bitmap for file:/an/image.jpg transformed by Matrix[pre=[], set={}, post=[]]\n" + "Bitmap for file:/an/image.jpg transformed by Matrix[pre=[], set={}, post=[]]", shadowOf(canvas).getDescription()); assertEquals("Bitmap for file:/an/image.jpg transformed by Matrix[pre=[], set={}, post=[]]\n" + "Bitmap for file:/an/image.jpg transformed by Matrix[pre=[], set={}, post=[]]", shadowOf(targetBitmap).getDescription()); }
@Test public void testSetScale() { final Matrix matrix = new Matrix(); matrix.setScale(2.0f, 2.0f); assertPointsEqual(mapPoint(matrix, 1.0f, 1.0f), new PointF(2.0f, 2.0f)); matrix.setScale(-2.0f, -3.0f); assertPointsEqual(mapPoint(matrix, 2.0f, 3.0f), new PointF(-4.0f, -9.0f)); matrix.setScale(-2.0f, -3.0f, 1.0f, 1.0f); assertPointsEqual(mapPoint(matrix, 2.0f, 3.0f), new PointF(-1.0f, -5.0f)); }
@Test public void testSetTranslate() { final Matrix matrix = new Matrix(); matrix.setTranslate(2.0f, 2.0f); assertPointsEqual(mapPoint(matrix, 1.0f, 1.0f), new PointF(3.0f, 3.0f)); matrix.setTranslate(-2.0f, -2.0f); assertPointsEqual(mapPoint(matrix, 1.0f, 1.0f), new PointF(-1.0f, -1.0f)); }
@Test public void preOperationsAreStacked() { Matrix m = new Matrix(); m.preRotate(4, 8, 15); m.preTranslate(16, 23); m.preSkew(42, 108); assertThat(shadowOf(m).getPreOperations()).containsExactly( "skew 42.0 108.0", "translate 16.0 23.0", "rotate 4.0 8.0 15.0" ); }
@Test public void setOperationsOverride() { Matrix m = new Matrix(); m.setRotate(4); m.setRotate(8); m.setRotate(15); m.setRotate(16); m.setRotate(23); m.setRotate(42); m.setRotate(108); assertThat(shadowOf(m).getSetOperations()).containsEntry("rotate", "108.0"); }