use of android.graphics.Matrix in project robolectric by robolectric.
the class ShadowCanvasTest method shouldDescribeBitmapDrawing_WithMatrix.
@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());
}
use of android.graphics.Matrix in project picasso by square.
the class BitmapHunterTest method centerInsideWideTooLarge.
@Test
public void centerInsideWideTooLarge() {
Bitmap source = Bitmap.createBitmap(50, 100, ARGB_8888);
Request data = new Request.Builder(URI_1).resize(50, 50).centerInside().build();
Bitmap result = transformResult(data, source, 0);
ShadowBitmap shadowBitmap = shadowOf(result);
assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source);
Matrix matrix = shadowBitmap.getCreatedFromMatrix();
ShadowMatrix shadowMatrix = shadowOf(matrix);
assertThat(shadowMatrix.getPreOperations()).containsOnly("scale 0.5 0.5");
}
use of android.graphics.Matrix in project picasso by square.
the class BitmapHunterTest method exifRotationSizing.
@Test
public void exifRotationSizing() throws Exception {
Request data = new Request.Builder(URI_1).resize(5, 10).build();
Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);
Bitmap result = transformResult(data, source, ORIENTATION_ROTATE_90);
ShadowBitmap shadowBitmap = shadowOf(result);
assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source);
Matrix matrix = shadowBitmap.getCreatedFromMatrix();
ShadowMatrix shadowMatrix = shadowOf(matrix);
assertThat(shadowMatrix.getPreOperations()).contains("scale 1.0 0.5");
}
use of android.graphics.Matrix in project picasso by square.
the class BitmapHunterTest method centerCropResultMatchesTargetSize.
@Test
public void centerCropResultMatchesTargetSize() {
Request request = new Request.Builder(URI_1).resize(1080, 642).centerCrop().build();
Bitmap source = Bitmap.createBitmap(640, 640, ARGB_8888);
Bitmap result = transformResult(request, source, 0);
ShadowBitmap shadowBitmap = shadowOf(result);
Matrix matrix = shadowBitmap.getCreatedFromMatrix();
ShadowMatrix shadowMatrix = shadowOf(matrix);
String scalePreOperation = shadowMatrix.getPreOperations().get(0);
assertThat(scalePreOperation).startsWith("scale ");
float scaleX = Float.valueOf(scalePreOperation.split(" ")[1]);
float scaleY = Float.valueOf(scalePreOperation.split(" ")[2]);
int transformedWidth = Math.round(result.getWidth() * scaleX);
int transformedHeight = Math.round(result.getHeight() * scaleY);
assertThat(transformedWidth).isEqualTo(1080);
assertThat(transformedHeight).isEqualTo(642);
}
use of android.graphics.Matrix in project picasso by square.
the class BitmapHunterTest method centerInsideWideTooSmall.
@Test
public void centerInsideWideTooSmall() {
Bitmap source = Bitmap.createBitmap(10, 20, ARGB_8888);
Request data = new Request.Builder(URI_1).resize(50, 50).centerInside().build();
Bitmap result = transformResult(data, source, 0);
ShadowBitmap shadowBitmap = shadowOf(result);
assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source);
Matrix matrix = shadowBitmap.getCreatedFromMatrix();
ShadowMatrix shadowMatrix = shadowOf(matrix);
assertThat(shadowMatrix.getPreOperations()).containsOnly("scale 2.5 2.5");
}
Aggregations