android 圆角图标 和不规则圆角(边框)

android 圆角图标 和不规则圆角(边框)_第1张图片

需要求就是如图 所示

将 原图 变成 圆角 或者不规则的形状,应为桌面主题需要用到。

当然 方法很多 这边提供如下方法。

// 圓角    private Bitmap getRoundedCornerBitmap(Bitmap bitmap) {        Bitmap roundBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);        Canvas canvas = new Canvas(roundBitmap);        int color = 0xff424242;        Paint paint = new Paint();        Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());        RectF rectF = new RectF(rect);        float roundPx = 50;        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 roundBitmap;    }    // 不规则角    private Bitmap getRoundedCornerBitmap(Bitmap bitmap, Bitmap bg) {        Paint paint = new Paint();        float scaleX = (float) (bitmap.getWidth() * 1.0 / bg.getWidth()) + 0.1f;        float scaleY = (float) (bitmap.getHeight() * 1.0 / bg.getHeight()) + 0.1f;        Bitmap scaleBitmap = scaleBitmap(bg, scaleX, scaleY);        Bitmap roundBitmap = Bitmap.createBitmap(scaleBitmap.getWidth(), scaleBitmap.getHeight(), Config.ARGB_8888);        Canvas canvas = new Canvas(roundBitmap);        paint.setAntiAlias(true);        canvas.drawBitmap(scaleBitmap, 0, 0, paint);        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));        canvas.drawBitmap(bitmap, scaleBitmap.getWidth() / 2 - bitmap.getWidth() / 2, scaleBitmap.getHeight() / 2                - bitmap.getHeight() / 2, paint);        return roundBitmap;    }

DEMO 下载地址

更多相关文章

  1. Android模拟、实现、触发系统按键事件的方法
  2. android 2.2+ 完全退出程序的方法
  3. android MediaPlayer出现RuntimeException: failure code: -38崩
  4. android 设置壁纸几种方法
  5. Android学习札记17:ImageView中的setImageBitmap()方法
  6. Anfdroid网络编程方法
  7. Android:解决列表滚动时背景色变黑的方法
  8. 把android平板USB上输出LOG方法
  9. Windows下Android开发环境配置的一种方法

随机推荐

  1. 几行代码看程序员的水平——Android文件
  2. 绕过身份检测,破解Android(安卓)SU
  3. android:layout_weight的真实含义
  4. Android之android:launchMode
  5. 在Android里完美实现基站和WIFI定位
  6. android aidl详解
  7. android 数据库 SQLiteOpenHelper和Conte
  8. MySQL和连接相关的timeout 的详细整理
  9. 5个保护MySQL数据仓库的小技巧
  10. mysql中url时区的陷阱该如何规避详解