获取圆角位图的方法
2016-03-12 16:47
344 查看
/**
* 获取圆角位图的方法
*
* @param bitmap
* 需要转化成圆角的位图
* @param pixels
* 圆角的度数,数值越大,圆角越大
* @return 处理后的圆角位图
*/
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;
}
public static void setBackGp(Context c, ImageView imageView) {
Drawable drawable = c.getResources().getDrawable(R.drawable.my_guanyu);
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Bitmap bitmap = bitmapDrawable.getBitmap();
BitmapDrawable bbb = new BitmapDrawable(toRoundCorner(bitmap, 35));
imageView.setBackgroundDrawable(bbb);
}
* 获取圆角位图的方法
*
* @param bitmap
* 需要转化成圆角的位图
* @param pixels
* 圆角的度数,数值越大,圆角越大
* @return 处理后的圆角位图
*/
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;
}
public static void setBackGp(Context c, ImageView imageView) {
Drawable drawable = c.getResources().getDrawable(R.drawable.my_guanyu);
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Bitmap bitmap = bitmapDrawable.getBitmap();
BitmapDrawable bbb = new BitmapDrawable(toRoundCorner(bitmap, 35));
imageView.setBackgroundDrawable(bbb);
}
相关文章推荐
- 使用dom4j解析XML文档
- 蓝桥杯 algo_5 最短路 (bellman,SPFA)
- 2015年Java开发岗位面试题归类
- 【转】QT之菜单栏QMenu,下拉菜单QAction,工具栏QToolBar的使用
- Makefile之 .PHONY 作用
- GCC基本用法
- HDU 1158 dp
- 杭电Problem-1716 排列2 next_permutation
- 三个水杯
- SQOOP 操作
- Java中的迭代器
- 分数拆分(枚举)
- 1002 A + B Problem II [ACM刷题]
- 循环语句(3)
- NSURLSession简介
- 新的开始
- CentOS6.5 下Redis 安装
- 图片压缩大全及二次采样
- 校内互测 选数字
- swift 自定义图片轮播视图