60 lines
2.1 KiB
Java
60 lines
2.1 KiB
Java
package com.ubt.jimu.connect.view;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Paint;
|
|
import android.graphics.PorterDuff;
|
|
import android.graphics.PorterDuffXfermode;
|
|
import android.graphics.Rect;
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.util.AttributeSet;
|
|
import androidx.appcompat.widget.AppCompatImageView;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class CircleImageView extends AppCompatImageView {
|
|
private Paint c;
|
|
|
|
public CircleImageView(Context context) {
|
|
this(context, null);
|
|
}
|
|
|
|
private Bitmap a(Bitmap bitmap, int i) {
|
|
Bitmap createBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
|
|
Canvas canvas = new Canvas(createBitmap);
|
|
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
|
|
this.c.setAntiAlias(true);
|
|
canvas.drawARGB(0, 0, 0, 0);
|
|
this.c.setColor(-12434878);
|
|
float width = bitmap.getWidth() / 2;
|
|
canvas.drawCircle(width, width, width, this.c);
|
|
this.c.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
|
canvas.drawBitmap(bitmap, rect, rect, this.c);
|
|
return createBitmap;
|
|
}
|
|
|
|
@Override // android.widget.ImageView, android.view.View
|
|
protected void onDraw(Canvas canvas) {
|
|
Drawable drawable = getDrawable();
|
|
if (drawable == null) {
|
|
super.onDraw(canvas);
|
|
return;
|
|
}
|
|
Bitmap a = a(((BitmapDrawable) drawable).getBitmap(), 14);
|
|
Rect rect = new Rect(0, 0, a.getWidth(), a.getHeight());
|
|
Rect rect2 = new Rect(0, 0, getWidth(), getHeight());
|
|
this.c.reset();
|
|
canvas.drawBitmap(a, rect, rect2, this.c);
|
|
}
|
|
|
|
public CircleImageView(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, 0);
|
|
}
|
|
|
|
public CircleImageView(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
this.c = new Paint();
|
|
}
|
|
}
|