public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {                    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);          Canvas canvas = new Canvas(output);            final int color = 0xff424242;          final Paint paint = new Paint();          final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());          final RectF rectF = new RectF(rect);          final float roundPx = pixels;            paint.setAntiAlias(true);          canvas.drawARGB(0, 0, 0, 0);          paint.setColor(color);          canvas.drawRoundRect(rectF, roundPx, roundPx, paint);            paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));          canvas.drawBitmap(bitmap, rect, rect, paint);            return output;      }



使用示例:
 LinearLayout layout = (LinearLayout) findViewById(R.id.layout);        Drawable drawable = getResources().getDrawable(R.drawable.bg);        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;        Bitmap bitmap = bitmapDrawable.getBitmap();                BitmapDrawable bbb = new BitmapDrawable(toRoundCorner(bitmap, 30));        layout.setBackgroundDrawable(bbb);


更多相关文章

  1. Android和iPhone应用程序界面布局示例
  2. Android列表控件Spinner简单用法示例
  3. Android ApiDemos示例解析(91):OS->SMS Messaging
  4. Android 使用Loader示例
  5. Android 官方示例:android-architecture 学习笔记(三)之todo-mvp-

随机推荐

  1. Android中TextView中加图片,超链接,一部分
  2. Android(安卓)Window PhoneWindow DecorV
  3. Android中http请求(C# MVC接收)
  4. Android(安卓)通过power键关机重启的流程
  5. android 全屏 webview 加载的h5的输入框,
  6. selector下的按钮介绍
  7. android json解析
  8. 6. ToggleButton&Switch
  9. Android(安卓)的 广播注册(一)
  10. Android——GSON解析JSON