|
@@ -32,6 +32,11 @@ import android.content.res.Resources;
|
|
|
import android.graphics.Bitmap;
|
|
|
import android.graphics.Canvas;
|
|
|
import android.graphics.Color;
|
|
|
+import android.graphics.Paint;
|
|
|
+import android.graphics.PorterDuff;
|
|
|
+import android.graphics.PorterDuffXfermode;
|
|
|
+import android.graphics.Rect;
|
|
|
+import android.graphics.RectF;
|
|
|
import android.graphics.Typeface;
|
|
|
import android.graphics.drawable.Animatable;
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
@@ -164,21 +169,28 @@ public class DisplayUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static Drawable getRoundedDrawable(Drawable drawable) {
|
|
|
- Bitmap bitmap = getBitmap(drawable);
|
|
|
- new RoundAsCirclePostprocessor(true).process(bitmap);
|
|
|
- return new BitmapDrawable(bitmap);
|
|
|
- }
|
|
|
+ public static Bitmap roundBitmap(Bitmap bitmap) {
|
|
|
+ Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
|
|
|
|
|
|
- public static Bitmap getRoundedBitmapFromVectorDrawableResource(Resources resources, int resource) {
|
|
|
- VectorDrawable vectorDrawable = (VectorDrawable) ResourcesCompat.getDrawable(resources, resource, null);
|
|
|
- Bitmap bitmap = getBitmap(vectorDrawable);
|
|
|
- new RoundPostprocessor(true).process(bitmap);
|
|
|
- return bitmap;
|
|
|
+ final Canvas canvas = new Canvas(output);
|
|
|
+
|
|
|
+ final Paint paint = new Paint();
|
|
|
+ final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
|
|
|
+ final RectF rectF = new RectF(rect);
|
|
|
+
|
|
|
+ paint.setAntiAlias(true);
|
|
|
+ canvas.drawARGB(0, 0, 0, 0);
|
|
|
+ canvas.drawOval(rectF, paint);
|
|
|
+
|
|
|
+ paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
|
|
+ canvas.drawBitmap(bitmap, rect, rect, paint);
|
|
|
+
|
|
|
+ return output;
|
|
|
}
|
|
|
|
|
|
- public static Drawable getRoundedBitmapDrawableFromVectorDrawableResource(Resources resources, int resource) {
|
|
|
- return new BitmapDrawable(getRoundedBitmapFromVectorDrawableResource(resources, resource));
|
|
|
+ public static Drawable getRoundedDrawable(Drawable drawable) {
|
|
|
+ Bitmap bitmap = getBitmap(drawable);
|
|
|
+ return new BitmapDrawable(roundBitmap(bitmap));
|
|
|
}
|
|
|
|
|
|
public static Bitmap getBitmap(Drawable drawable) {
|