Android常用功能

将Bitmap转成圆形的Bitmap

2017-12-13  本文已影响16人  龙儿筝
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;
  }
上一篇下一篇

猜你喜欢

热点阅读