diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/RoundedCorners.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/RoundedCorners.java index be3e804a28..0e0ce2622a 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/RoundedCorners.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/RoundedCorners.java @@ -5,6 +5,7 @@ import android.support.annotation.NonNull; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; import com.bumptech.glide.util.Preconditions; +import com.bumptech.glide.util.Util; import java.nio.ByteBuffer; import java.security.MessageDigest; @@ -51,18 +52,22 @@ public RoundedCorners(@SuppressWarnings("unused") Context context, int roundingR @Override protected Bitmap transform( @NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { - return TransformationUtils.roundedCorners(pool, toTransform, outWidth, outHeight, - roundingRadius); + return TransformationUtils.roundedCorners(pool, toTransform, roundingRadius); } @Override public boolean equals(Object o) { - return (o instanceof RoundedCorners) && ((RoundedCorners) o).roundingRadius == roundingRadius; + if (o instanceof RoundedCorners) { + RoundedCorners other = (RoundedCorners) o; + return roundingRadius == other.roundingRadius; + } + return false; } @Override public int hashCode() { - return ID.hashCode() + roundingRadius; + return Util.hashCode(ID.hashCode(), + Util.hashCode(roundingRadius)); } @Override diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/TransformationUtils.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/TransformationUtils.java index 671fb7816a..881d0a5c1c 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/TransformationUtils.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/TransformationUtils.java @@ -14,6 +14,7 @@ import android.os.Build; import android.support.annotation.NonNull; import android.util.Log; +import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; import com.bumptech.glide.util.Preconditions; import com.bumptech.glide.util.Synthetic; @@ -397,16 +398,41 @@ private static Bitmap getAlphaSafeBitmap(@NonNull BitmapPool pool, * @param roundingRadius the corner radius to be applied (in device-specific pixels). * @return a {@link Bitmap} similar to inBitmap but with rounded corners. * @throws IllegalArgumentException if roundingRadius, width or height is 0 or less. + * + * @deprecated Width and height are unused and ignored. Use + * {@link #roundedCorners(BitmapPool, Bitmap, int)} instead. + */ + @Deprecated + public static Bitmap roundedCorners( + @NonNull BitmapPool pool, + @NonNull Bitmap inBitmap, + @SuppressWarnings("unused") int width, + @SuppressWarnings("unused") int height, + int roundingRadius) { + return roundedCorners(pool, inBitmap, roundingRadius); + } + + /** + * Creates a bitmap from a source bitmap and rounds the corners. + * + *

This method does NOT resize the given {@link Bitmap}, it only rounds it's corners. + * To both resize and round the corners of an image, consider + * {@link com.bumptech.glide.request.RequestOptions#transforms(Transformation[])} and/or + * {@link com.bumptech.glide.load.MultiTransformation}. + * + * @param inBitmap the source bitmap to use as a basis for the created bitmap. + * @param roundingRadius the corner radius to be applied (in device-specific pixels). + * @return a {@link Bitmap} similar to inBitmap but with rounded corners. + * @throws IllegalArgumentException if roundingRadius, width or height is 0 or less. */ - public static Bitmap roundedCorners(@NonNull BitmapPool pool, @NonNull Bitmap inBitmap, - int width, int height, int roundingRadius) { - Preconditions.checkArgument(width > 0, "width must be greater than 0."); - Preconditions.checkArgument(height > 0, "height must be greater than 0."); + public static Bitmap roundedCorners( + @NonNull BitmapPool pool, @NonNull Bitmap inBitmap, int roundingRadius) { Preconditions.checkArgument(roundingRadius > 0, "roundingRadius must be greater than 0."); // Alpha is required for this transformation. Bitmap toTransform = getAlphaSafeBitmap(pool, inBitmap); - Bitmap result = pool.get(width, height, Bitmap.Config.ARGB_8888); + Bitmap result = + pool.get(toTransform.getWidth(), toTransform.getHeight(), Bitmap.Config.ARGB_8888); result.setHasAlpha(true);