裁剪圓角圖片

public static Bitmap ReadBitmap(byte[] byt) {
  BitmapFactory.Options options = new BitmapFactory.Options();
  options.inPreferredConfig = Config.ARGB_8888;
  options.inInputShareable = true;
  options.inPurgeable = true;
  Bitmap bitmap = BitmapFactory.decodeByteArray(byt, 0, byt.length);
 
  /**
   * 以下爲裁剪圓角圖片
   *
   * */
  int w = bitmap.getWidth();
  int h = bitmap.getHeight();
  Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888);
  Canvas canvas = new Canvas(output);
  final int color = 0xff424242;
  final Paint paint = new Paint();
  final Rect rect = new Rect(0, 0, w, h);
  final RectF rectF = new RectF(rect);
  paint.setAntiAlias(true);
  canvas.drawARGB(0, 0, 0, 0);
  paint.setColor(color);
  canvas.drawRoundRect(rectF, 10, 10, paint);
  paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
  canvas.drawBitmap(bitmap, rect, rect, paint);
  return output;
 }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章