有人用过RoundedBitmapDrawable
吗?如果我错了,请纠正我,但据我了解,它是从常规矩形图像生成圆形图像。
到目前为止我尝试过的是这个
RoundedBitmapDrawable.createRoundedBitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), iconResource))
我试图实现的目标:将任何图像转换为圆形图像并使用 ImageView 显示它。
万一我把事情搞混了,我说的都是胡说八道。是否有可能(或更简单)使用任何新框架来做到这一点? (Android L 或新的支持库)
最佳答案
你需要设置圆角半径。
Resources res = getResources();
Bitmap src = BitmapFactory.decodeResource(res, iconResource);
RoundedBitmapDrawable dr =
RoundedBitmapDrawableFactory.create(res, src);
dr.setCornerRadius(Math.max(src.getWidth(), src.getHeight()) / 2.0f);
imageView.setImageDrawable(dr);
关于android - 如何使用圆角 BitmapDrawable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24878740/