android 如何用代码生成圆角Bitmap图片

//生成圆角图片
 public static Bitmap GetRoundedCornerBitmap(Bitmap bitmap) {
  try {
   Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
     bitmap.getHeight(), Config.ARGB_8888);
   Canvas canvas = new Canvas(output);     
   final Paint paint = new Paint();
   final Rect rect = new Rect(0, 0, bitmap.getWidth(),
     bitmap.getHeight());  
   final RectF rectF = new RectF(new Rect(0, 0, bitmap.getWidth(),
     bitmap.getHeight()));
   final float roundPx = 14;//设置这 可以改变取舍多少幅度
   paint.setAntiAlias(true);
   canvas.drawARGB(0, 0, 0, 0);
   paint.setColor(Color.BLACK);  
   canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
   paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));    
 
   final Rect src = new Rect(0, 0, bitmap.getWidth(),
     bitmap.getHeight());
   
   canvas.drawBitmap(bitmap, src, rect, paint); 
   return output;
  } catch (Exception e) {   
   return bitmap;
  }
 }

你可能感兴趣的:(android 如何用代码生成圆角Bitmap图片)