如何使用 RoundedBitmapDrawable [英] How to use RoundedBitmapDrawable
本文介绍了如何使用 RoundedBitmapDrawable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人使用过 RoundedBitmapDrawable
吗?如果我错了,请纠正我,但据我所知,它从常规矩形图像生成圆形图像.
Has anyone managed to use RoundedBitmapDrawable
? Correct me if I'm wrong, but to my understanding, it makes a circular image from a regular rectangular image.
到目前为止我尝试过的是这个
What I've tried so far is this
RoundedBitmapDrawable.createRoundedBitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), iconResource))
我试图实现的目标:将任何图像转换为圆形图像并使用 ImageView 显示它.
What I tried to achieve: transform any image to a circular image and show it using an ImageView.
万一我把事情搞混了,我说的都是胡说八道.是否有可能(或更简单)使用任何新框架来做到这一点?(Android L 或新的支持库)
In case I mixed things up and all that I said is non-sense. Is it possible (or simpler) to do it with any of the new framework? (Android L or new Support Library)
推荐答案
需要设置圆角半径.
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);
这篇关于如何使用 RoundedBitmapDrawable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文