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=[]]");
}
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);
}
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);
}
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=[]]");
}
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));
}
Aggregations