Glide加载图片成圆角
来源:互联网 发布:oracle数据库监控工具 编辑:程序博客网 时间:2024/06/05 11:24
Google推荐的图片加载库Glide介绍
导入库
dependencies {
compile 'com.github.bumptech.glide:glide:4.0.0-RC0'
}
加载图片的方式
Glide.with(mContext) .load(image) .into(view);如果需要加载圆角图片则需要重写
BitmapTransformation
public class GlideRoundTransform extends BitmapTransformation { private static float radius = 0f; public GlideRoundTransform(Context context) { this(context, 4); } public GlideRoundTransform(Context context, int dp) { super(context); this.radius = Resources.getSystem().getDisplayMetrics().density * dp; } @Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { Bitmap bitmap = TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight); return roundCrop(pool, bitmap); } private static Bitmap roundCrop(BitmapPool pool, Bitmap source) { if (source == null) return null; Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight()); canvas.drawRoundRect(rectF, radius, radius, paint); return result; } public String getId() { return getClass().getName() + Math.round(radius); } @Override public void updateDiskCacheKey(MessageDigest messageDigest) { }
然后加载
RequestOptions myOptions = new RequestOptions() .centerCrop() .transform(new GlideRoundTransform(mContext, 8)); ImageView view = getView(viewId); Glide.with(mContext) .load(Utils.getImageUrl(url)) .apply(myOptions) .into(view);
阅读全文
0 0
- Glide加载图片成圆角
- 图片加载库Glide
- Android Glide 图片加载
- Glide加载图片
- 图片加载库Glide
- 图片加载库Glide
- 图片加载框架Glide
- Glide图片加载
- Glide图片加载
- Glide 加载图片变形
- Glide加载图片
- Glide 图片加载
- glide 图片加载
- Glide加载图片类型
- Glide图片加载
- 使用glide加载图片
- Glide图片加载
- Glide加载https图片
- pyspark-Collaborative 过滤
- 第五周项目2---建立链栈算法库
- 《PHP高级知识进阶》系列技术文章整理收藏
- ion-chip 标签
- java的跨平台原理
- Glide加载图片成圆角
- 微信开发学习笔记(一):前端图片缓存问题
- SpringBoot——run启动流程
- HTTPS入门及如何防重放攻击
- TCP协议中的三次握手和四次挥手(图解)
- 如何成为一个技术全面的架构师
- PHP中获取文件扩展名的N种方法
- 一个数除以0一定报错么
- JVM读书笔记之Java代码编译过程