圆形圆角图片

本文介绍了如何在Android中创建圆形和圆角图片。通过参考BitmapShader实战,可以实现自定义圆形图片效果。此外,推荐使用开源库SelectableRoundedImageView和RoundedImageView,它们提供了方便的API来轻松实现圆角图片功能。在Android Studio中,可以通过添加相应的依赖来使用这些库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1,单个图片

 public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.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);
        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        canvas.drawRoundRect(rectF, (float) pixels, (float) pixels, paint);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);
        return output;
    }

2,一系列图片,继承imageview

参考博客:Android BitmapShader 实战 实现圆形、圆角图片

开源控件:SelectableRoundedImageView——Android图片圆角类库

as中引用:compile 'com.joooonho:selectableroundedimageview:1.0.1'

 compile 'com.makeramen:roundedimageview:2.1.2'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值