Android利用glide加载圆形图片,头像的实现
2016-12-20 10:44
1116 查看
主要是用到了RoundedBitmapDrawable这个类是Drawable的一个子抽象类
可以实现从文件路径,输入流或bitmap 的对象都可以转换成圆形,或圆角,就不用使用第三方了,很方便
如果要转换成圆形,要用到下面这个方法;
下面这个是类的说明,可以看一下
具体的使用如下配合glide
可以实现从文件路径,输入流或bitmap 的对象都可以转换成圆形,或圆角,就不用使用第三方了,很方便
如果要转换成圆形,要用到下面这个方法;
/** * Sets the image shape to circular. * <p>This overwrites any calls made to {@link #setCornerRadius(float)} so far.</p> */ public void setCircular(boolean circular) { mIsCircular = circular; mApplyGravity = true; if (circular) { updateCircularCornerRadius(); mPaint.setShader(mBitmapShader); invalidateSelf(); } else { setCornerRadius(0); } }
下面这个是类的说明,可以看一下
/** * A Drawable that wraps a bitmap and can be drawn with rounded corners. You can create a * RoundedBitmapDrawable from a file path, an input stream, or from a * {@link android.graphics.B或itmap} object. * <p> * Also see the {@link android.graphics.Bitmap} class, which handles the management and * transformation of raw bitmap graphics, and should be used when drawing to a * {@link android.graphics.Canvas}. * </p> */
具体的使用如下配合glide
//加载圆形头像 Glide.with(context).load(data.get(position).getMenu_img().toString()) .asBitmap().centerCrop().into(new BitmapImageViewTarget(holder.gridIcon) { @Override ce5c protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(context.getResources(), resource); circularBitmapDrawable.setCircular(true); holder.gridIcon.setImageDrawable(circularBitmapDrawable); } });
相关文章推荐
- Android 自定义圆形头像CircleImageView支持加载网络图片的实现代码
- Android Glide+CircleImageView实现加载圆形图片列表
- Android开发:使用Glide动态加载圆形图片和圆角图片
- Android图片加载神器之Fresco-圆形圆角二合一[Java代码实现圆形圆角效果]
- Android开发:使用Glide动态加载圆形图片和圆角图片
- android ImageView 实现圆形图片(QQ头像)
- android圆形头像:相机相册加载图片到圆形头像
- Android利用CircleImageView实现圆形头像效果
- Android View加载圆形图片且同时绘制圆形图片的外部边缘边线及边框:LayerDrawable实现
- Android 使用Glide动态加载圆形图片和圆角图片
- Android利用Gallery和ImageSwitcher实现在线相册图片预览功能(异步加载图片)
- android 利用ImagevView加载本地图片并实现等比缩放
- Android图片加载神器之Fresco-Java代码实现圆形圆角效果
- android圆形图片,圆形头像实现方法(可直接运用到工程中)
- Android图片加载神器之Fresco-圆形圆角二合一[Java代码实现圆形圆角效果]
- Android实现本地上传图片并设置为圆形头像
- Android开发:使用Glide动态加载圆形图片和圆角图片--图片开发框架
- Android实现本地上传图片并设置为圆形头像
- Android开发之利用Volley加载圆形图片
- Android相册,利用LruCache、DiskLruCache实现图片的加载,避免出现OOM