Search in sources :

Example 51 with Matrix

use of android.graphics.Matrix in project robolectric by robolectric.

the class ShadowBitmapTest method shouldReceiveDescriptionWhenDrawingToCanvasWithBitmapAndMatrixAndPaint.

@Test
public void shouldReceiveDescriptionWhenDrawingToCanvasWithBitmapAndMatrixAndPaint() throws Exception {
    Bitmap bitmap1 = create("Bitmap One", 100, 100);
    Bitmap bitmap2 = create("Bitmap Two", 100, 100);
    Canvas canvas = new Canvas(bitmap1);
    canvas.drawBitmap(bitmap2, new Matrix(), null);
    assertThat(shadowOf(bitmap1).getDescription()).isEqualTo("Bitmap One\nBitmap Two transformed by Matrix[pre=[], set={}, post=[]]");
}
Also used : Bitmap(android.graphics.Bitmap) ColorMatrix(android.graphics.ColorMatrix) Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) Test(org.junit.Test)

Example 52 with Matrix

use of android.graphics.Matrix in project robolectric by robolectric.

the class ShadowBitmapTest method shouldAdjustDimensionsForMatrix.

@Test
public void shouldAdjustDimensionsForMatrix() {
    Bitmap transformedBitmap;
    int width = 10;
    int height = 20;
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Matrix matrix = new Matrix();
    transformedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, false);
    assertThat(transformedBitmap.getWidth()).isEqualTo(width);
    assertThat(transformedBitmap.getHeight()).isEqualTo(height);
    matrix.setRotate(90);
    transformedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, false);
    assertThat(transformedBitmap.getWidth()).isEqualTo(height);
    assertThat(transformedBitmap.getHeight()).isEqualTo(width);
    matrix.setScale(2, 3);
    transformedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, false);
    assertThat(transformedBitmap.getWidth()).isEqualTo(width * 2);
    assertThat(transformedBitmap.getHeight()).isEqualTo(height * 3);
}
Also used : Bitmap(android.graphics.Bitmap) ColorMatrix(android.graphics.ColorMatrix) Matrix(android.graphics.Matrix) Paint(android.graphics.Paint) Test(org.junit.Test)

Example 53 with Matrix

use of android.graphics.Matrix in project robolectric by robolectric.

the class ShadowBitmapTest method shouldGetPixelsFromAnyNonNullableCreatedBitmap.

@Test
public void shouldGetPixelsFromAnyNonNullableCreatedBitmap() {
    Bitmap bitmap;
    int width = 10;
    int height = 10;
    int[] pixels = new int[width * height];
    bitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    bitmap = Bitmap.createBitmap(bitmap);
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height);
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, new Matrix(), false);
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    bitmap = Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888);
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
}
Also used : Bitmap(android.graphics.Bitmap) ColorMatrix(android.graphics.ColorMatrix) Matrix(android.graphics.Matrix) Paint(android.graphics.Paint) Test(org.junit.Test)

Example 54 with Matrix

use of android.graphics.Matrix in project robolectric by robolectric.

the class ShadowBitmapTest method shouldReceiveDescriptionWhenDrawABitmapToCanvasWithAPaintEffect.

@Test
public void shouldReceiveDescriptionWhenDrawABitmapToCanvasWithAPaintEffect() throws Exception {
    Bitmap bitmap1 = create("Bitmap One", 100, 100);
    Bitmap bitmap2 = create("Bitmap Two", 100, 100);
    Canvas canvas = new Canvas(bitmap1);
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix()));
    canvas.drawBitmap(bitmap2, new Matrix(), paint);
    assertThat(shadowOf(bitmap1).getDescription()).isEqualTo("Bitmap One\n" + "Bitmap Two with ColorMatrixColorFilter<1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0>" + " transformed by Matrix[pre=[], set={}, post=[]]");
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) ColorMatrix(android.graphics.ColorMatrix) Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint) Test(org.junit.Test)

Example 55 with Matrix

use of android.graphics.Matrix in project robolectric by robolectric.

the class ShadowCanvasTest method visualize_shouldReturnDescription.

@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));
}
Also used : Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Test(org.junit.Test)

Aggregations

Matrix (android.graphics.Matrix)970 Bitmap (android.graphics.Bitmap)254 Paint (android.graphics.Paint)201 RectF (android.graphics.RectF)155 Rect (android.graphics.Rect)99 Test (org.junit.Test)93 Canvas (android.graphics.Canvas)80 ImageView (android.widget.ImageView)67 View (android.view.View)65 Point (android.graphics.Point)52 Bundle (android.os.Bundle)45 GhostView (android.view.GhostView)40 ViewGroup (android.view.ViewGroup)39 ColorMatrix (android.graphics.ColorMatrix)38 Drawable (android.graphics.drawable.Drawable)38 IOException (java.io.IOException)38 BitmapHunter.forRequest (com.squareup.picasso.BitmapHunter.forRequest)36 TestUtils.makeBitmap (com.squareup.picasso.TestUtils.makeBitmap)36 ShadowBitmap (org.robolectric.shadows.ShadowBitmap)36 ShadowMatrix (org.robolectric.shadows.ShadowMatrix)36