android 头像球_android自定义控件之圆形头像

importandroid.content.Context;importandroid.graphics.Bitmap;importandroid.graphics.Canvas;importandroid.graphics.Paint;importandroid.graphics.PorterDuff;importandroid.graphics.PorterDuffXfermode;importandroid.graphics.Xfermode;importandroid.graphics.drawable.Drawable;importandroid.util.AttributeSet;importandroid.widget.ImageView;public abstract class MaskedImage extendsImageView {private static finalXfermode MASK_XFERMODE;privateBitmap mask;privatePaint paint;static{

PorterDuff.Mode localMode=PorterDuff.Mode.DST_IN;

MASK_XFERMODE= newPorterDuffXfermode(localMode);

}publicMaskedImage(Context paramContext) {super(paramContext);

}publicMaskedImage(Context paramContext, AttributeSet paramAttributeSet) {super(paramContext, paramAttributeSet);

}public MaskedImage(Context paramContext, AttributeSet paramAttributeSet, intparamInt) {super(paramContext, paramAttributeSet, paramInt);

}public abstractBitmap createMask();protected voidonDraw(Canvas paramCanvas) {

Drawable localDrawable=getDrawable();if (localDrawable == null)return;try{if (this.paint == null) {

Paint localPaint1= newPaint();this.paint =localPaint1;this.paint.setFilterBitmap(false);

Paint localPaint2= this.paint;

Xfermode localXfermode1=MASK_XFERMODE;

@SuppressWarnings("unused")

Xfermode localXfermode2=localPaint2.setXfermode(localXfermode1);

}float f1 =getWidth();float f2 =getHeight();int i = paramCanvas.saveLayer(0.0F, 0.0F, f1, f2, null, 31);int j =getWidth();int k =getHeight();

localDrawable.setBounds(0, 0, j, k);

localDrawable.draw(paramCanvas);if ((this.mask == null) || (this.mask.isRecycled())) {

Bitmap localBitmap1=createMask();this.mask =localBitmap1;

}

Bitmap localBitmap2= this.mask;

Paint localPaint3= this.paint;

paramCanvas.drawBitmap(localBitmap2,0.0F, 0.0F, localPaint3);

paramCanvas.restoreToCount(i);return;

}catch(Exception localException) {

StringBuilder localStringBuilder= newStringBuilder()

.append("Attempting to draw with recycled bitmap. View ID = ");

System.out.println("localStringBuilder=="+localStringBuilder);

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值