在Android开发中经常会遇到需要设置一个图片为圆形或者圆角矩形,这个时候会有许多的方法,如CircleImageView等等。
但是googke给我们提供了简便的方法,为什么不用呢?
RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getResources(), "xxx/0.jpg");
imageView.setImageDrawable(drawable);
// drawable.setCircular(true);//设置为圆形
drawable.setCornerRadius(50);//设置矩形的radius
RoundedBitmapDrawable有三个create方法,
1、reate(Resources res, String filepath)//加载本地图片,构成一个Drawable对象
2、create(Resources res, java.io.InputStream is)//从数据流里面获取图片信息构成一个Drawable对象
3、create(Resources res, Bitmap bitmap)//将bitmap转换成一个Drawable对象
当然,要用到该类,需要添加V4的支持库文件。