图片圆角

  //切图为圆角
    public static Bitmap removeYuanjiao(Bitmap bitmap,int pixels){
     int width = bitmap.getWidth();
     int height = bitmap.getHeight();
     Bitmap creBitmap = Bitmap.createBitmap(width, height, android.graphics.Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(creBitmap);
  Paint paint = new Paint();
  RectF rectF = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
  float roundPx = pixels;
  paint.setAntiAlias(true);
  canvas.drawARGB(0, 0, 0, 0);
  canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
  paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
  canvas.drawBitmap(bitmap, 0, 0, paint);
  return creBitmap;
    }
   
   
    //将图片去灰色
    public static Bitmap removeHuiDu(Bitmap bitmap){
     int width = bitmap.getWidth();
     int height = bitmap.getHeight();
     Bitmap creBitmap = Bitmap.createBitmap(width, height, android.graphics.Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(creBitmap);
  Paint paint = new Paint();
   ColorMatrix colorMatrix = new ColorMatrix();
         colorMatrix.setSaturation(0);
         ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix);
         paint.setColorFilter(colorMatrixFilter);
         canvas.drawBitmap(bitmap, 0, 0, paint);
     return creBitmap;
     
    }
   
    //去灰色圆角
    public static Bitmap HuiDuYuanJiao(Bitmap bitmap,int pixels){
     return removeYuanjiao(removeHuiDu(bitmap), pixels);
    }

你可能感兴趣的:(图片圆角)