use of android.graphics.Bitmap in project glide by bumptech.
the class CircleCropTest method testTransform_withNarrowRectangle.
@Test
public void testTransform_withNarrowRectangle() {
Bitmap redNarrowRectangle = createSolidRedBitmap(20, 50);
Bitmap result = circleCrop.transform(bitmapPool, redNarrowRectangle, 40, 80);
Bitmap expected = createBitmapWithRedCircle(40, 80);
assertSamePixels(expected, result);
}
use of android.graphics.Bitmap in project glide by bumptech.
the class CircleCropTest method createSolidRedBitmap.
private Bitmap createSolidRedBitmap(int width, int height) {
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setColor(Color.RED);
Rect rect = new Rect(0, 0, width, height);
canvas.drawRect(rect, paint);
return result;
}
use of android.graphics.Bitmap in project glide by bumptech.
the class TransformationUtilsTest method testFitCenterSetsOutBitmapToHaveAlphaIfInBitmapHasAlphaAndOutBitmapIsReused.
@Test
public void testFitCenterSetsOutBitmapToHaveAlphaIfInBitmapHasAlphaAndOutBitmapIsReused() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap toReuse = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
reset(bitmapPool);
when(bitmapPool.get(eq(toReuse.getWidth()), eq(toReuse.getHeight()), eq(toReuse.getConfig()))).thenReturn(toReuse);
toReuse.setHasAlpha(false);
toTransform.setHasAlpha(true);
Bitmap result = TransformationUtils.fitCenter(bitmapPool, toTransform, toReuse.getWidth(), toReuse.getHeight());
assertEquals(toReuse, result);
assertTrue(result.hasAlpha());
}
use of android.graphics.Bitmap in project glide by bumptech.
the class TransformationUtilsTest method testFitCenterSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha.
@Test
public void testFitCenterSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
toTransform.setHasAlpha(true);
Bitmap result = TransformationUtils.fitCenter(bitmapPool, toTransform, toTransform.getWidth() / 2, toTransform.getHeight() / 2);
assertTrue(result.hasAlpha());
}
use of android.graphics.Bitmap in project glide by bumptech.
the class TransformationUtilsTest method testFitCenterWithSmallWideBitmap.
@Test
public void testFitCenterWithSmallWideBitmap() {
final int maxSide = 500;
Bitmap smallWide = Bitmap.createBitmap(400, 40, Bitmap.Config.ARGB_8888);
Bitmap transformed = TransformationUtils.fitCenter(bitmapPool, smallWide, maxSide, maxSide);
assertHasOriginalAspectRatio(smallWide, transformed);
assertBitmapFitsExactlyWithinBounds(maxSide, transformed);
}
Aggregations