将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;
  }
    原文作者:龙儿筝
    原文地址: https://www.jianshu.com/p/fc0c4d70cab1
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞