如何使用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.
在情况下,我混的事情了,所有我说的是无感。是否有可能(或简单)与任何新的框架做呢? (安卓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屋!
查看全文