将Bitmap转成圆形的Bitmap

public static Bitmap getCircleBitmap(Bitmap bitmap) {
    int size = Math.min(bitmap.getWidth(), bitmap.getHeight());
    Bitmap circleBmp = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    Canvas canvasTmp = new Canvas(circleBmp);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    canvasTmp.drawCircle(size/2, size/2, size/2, paint);
    bitmap = Bitmap.createBitmap(bitmap, 0, 0, size, size);
    Canvas canvas = new Canvas(bitmap);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    canvas.drawBitmap(circleBmp, 0, 0, paint);
    return bitmap;
  }

你可能感兴趣的:(将Bitmap转成圆形的Bitmap)