private static Bitmap getCircleAvatar(Context context, Bitmap avatar) {
// TODO Auto-generated method stub
Bitmap bitmap=Bitmap.createBitmap(avatar.getWidth(), avatar.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas=new Canvas(bitmap);
Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);
//混合模式中的圆 DST
paint.setColor(Color.BLACK);
//半径取宽高中小的并/2
canvas.drawCircle(avatar.getWidth()/2, avatar.getHeight()/2,
avatar.getWidth()/2<avatar.getHeight()/2?avatar.getWidth()/2:avatar.getHeight()/2,
paint);
//添加混合模式给paint,矩阵,切圆,方形和圆形,选择圆形重叠的部分
//PorterDuffXfermode:该方法及是
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
//再把原始头像,画到bitmap上
canvas.drawBitmap(avatar, 0, 0, paint);
/**画个百边*/
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.STROKE);//设置一个模式
//进行单位变换
float strokeWidth =
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2,
context.getResources().getDisplayMetrics());
paint.setStrokeWidth(strokeWidth);
canvas.drawCircle(avatar.getWidth()/2, avatar.getHeight()/2,
avatar.getWidth()/2<avatar.getHeight()/2?avatar.getWidth()/2:avatar.getHeight()/2
-strokeWidth/2, paint);
return bitmap;
}
// TODO Auto-generated method stub
Bitmap bitmap=Bitmap.createBitmap(avatar.getWidth(), avatar.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas=new Canvas(bitmap);
Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);
//混合模式中的圆 DST
paint.setColor(Color.BLACK);
//半径取宽高中小的并/2
canvas.drawCircle(avatar.getWidth()/2, avatar.getHeight()/2,
avatar.getWidth()/2<avatar.getHeight()/2?avatar.getWidth()/2:avatar.getHeight()/2,
paint);
//添加混合模式给paint,矩阵,切圆,方形和圆形,选择圆形重叠的部分
//PorterDuffXfermode:该方法及是
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
//再把原始头像,画到bitmap上
canvas.drawBitmap(avatar, 0, 0, paint);
/**画个百边*/
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.STROKE);//设置一个模式
//进行单位变换
float strokeWidth =
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2,
context.getResources().getDisplayMetrics());
paint.setStrokeWidth(strokeWidth);
canvas.drawCircle(avatar.getWidth()/2, avatar.getHeight()/2,
avatar.getWidth()/2<avatar.getHeight()/2?avatar.getWidth()/2:avatar.getHeight()/2
-strokeWidth/2, paint);
return bitmap;
}