80,337
社区成员
发帖
与我相关
我的任务
分享
@Override
protected void onDraw(Canvas canvas)
{
Path clipPath = new Path();
clipPath.addCircle(getWidth()/2,getHeight()/2,Math.min(getWidth()/2,getHeight()/2),
Path.Direction.CW);
canvas.clipPath(clipPath);
super.onDraw(canvas);
}
private Bitmap circleBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff000000;
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
mPaint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
mPaint.setColor(color);
final int width = bitmap.getWidth();
canvas.drawCircle(width / 2, width / 2, width / 2, mPaint);
mPaint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, mPaint);//将图片绘制成白色图片
return output;
}