@Override protected Bitmap transform( @NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { return TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight); }
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { this.size = Math.max(outWidth, outHeight); return TransformationUtils.centerCrop(pool, toTransform, size, size); }
@Test public void testCenterCropReturnsGivenBitmapIfGivenBitmapExactlyMatchesGivenDimensions() { Bitmap toCrop = Bitmap.createBitmap(200, 300, Bitmap.Config.ARGB_8888); Bitmap transformed = TransformationUtils .centerCrop(bitmapPool, toCrop, toCrop.getWidth(), toCrop.getHeight()); // Robolectric incorrectly implements equals() for Bitmaps, we want the original object not // just an equivalent. assertTrue(toCrop == transformed); }
@Test @Config(sdk = 19) public void testCenterCropHandlesBitmapsWithNullConfigs() { Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565); toTransform.setConfig(null); Bitmap transformed = TransformationUtils.centerCrop(bitmapPool, toTransform, 50, 50); assertEquals(Bitmap.Config.ARGB_8888, transformed.getConfig()); }
@Test public void testCenterCropSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha() { Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); toTransform.setHasAlpha(true); Bitmap result = TransformationUtils.centerCrop(bitmapPool, toTransform, toTransform.getWidth() / 2, toTransform.getHeight() / 2); assertTrue(result.hasAlpha()); }
@Test public void testCenterCropSetsOutBitmapToNotHaveAlphaIfInBitmapDoesNotHaveAlpha() { Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); toTransform.setHasAlpha(false); Bitmap result = TransformationUtils.centerCrop(bitmapPool, toTransform, toTransform.getWidth() / 2, toTransform.getHeight() / 2); assertFalse(result.hasAlpha()); }
@Test public void testCenterCropSetsOutBitmapToHaveAlphaIfInBitmapHasAlphaAndOutBitmapIsReused() { 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(50), eq(50), eq(Bitmap.Config.ARGB_8888))) .thenReturn(toReuse); toReuse.setHasAlpha(false); toTransform.setHasAlpha(true); Bitmap result = TransformationUtils.centerCrop(bitmapPool, toTransform, toReuse.getWidth(), toReuse.getHeight()); assertEquals(toReuse, result); assertTrue(result.hasAlpha()); }
@Test public void testCenterCropSetsOutBitmapToNotHaveAlphaIfInBitmapDoesNotHaveAlphaAndOutBitmapIsReused() { 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(50), eq(50), eq(Bitmap.Config.ARGB_8888))).thenReturn(toReuse); toReuse.setHasAlpha(true); toTransform.setHasAlpha(false); Bitmap result = TransformationUtils.centerCrop(bitmapPool, toTransform, toReuse.getWidth(), toReuse.getHeight()); assertEquals(toReuse, result); assertFalse(result.hasAlpha()); }
@SuppressWarnings("PMD.CompareObjectsWithEquals") @Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { final Bitmap toReuse = pool.get(outWidth, outHeight, toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888); Bitmap transformed = TransformationUtils.centerCrop(toReuse, toTransform, outWidth, outHeight); if (toReuse != null && toReuse != transformed && !pool.put(toReuse)) { toReuse.recycle(); } return transformed; }
@SuppressWarnings("PMD.CompareObjectsWithEquals") @Override protected Bitmap transform( @NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { return TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight); }
@Override protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { Bitmap bitmap = TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight); return cornerTransform(pool, bitmap); }
@Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { Bitmap bitmap = TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight); return roundCrop(pool, bitmap); }
final Bitmap toReuse = pool.get(outWidth, outHeight, source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888); Bitmap transformed = TransformationUtils.centerCrop(toReuse, source, outWidth, outHeight); if (toReuse != null && toReuse != transformed && !pool.put(toReuse)) { toReuse.recycle();