圆形头像处理
很多上传头像是会用到圆形的头像,今天写了一个小方法,可以把图片处理成圆形的,感觉有用的直接拿去用:
不多说直接上代码,希望大家多多支持
//把图片处理成圆形
public Bitmap toRoundBitmap(Bitmap bitmap){
int width=bitmap.getWidth();
int height=bitmap.getHeight();
int r=0;
if (width<height){
r=width;
}else {
r=height;
}
Bitmap backgroundBitmap=Bitmap.createBitmap(width,height, Bitmap.Config.ARGB_8888);
Canvas canvas=new Canvas(backgroundBitmap);
Paint paint=new Paint();
paint.setAntiAlias(true);
RectF rectF=new RectF(0,0,r,r);
canvas.drawRoundRect(rectF,r/2,r/2,paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap,null,rectF,paint);
return backgroundBitmap;
}
还没有评论,来说两句吧...