您的位置:首页 > 其它

获取圆角位图的方法

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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: