安卓开发中Glide的基本使用

添加依赖

implementation 'com.github.bumptech.glide:glide:4.4.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.4.0'

最基础的,如果涉及到网络的话记得添加网络权限

Glide.with(BaseApplication.getContext()).load(url).into(imageView);

添加Options

Glide.with(BaseApplication.getContext()).load(url).apply(options).into(imageView);

Options有几种

1.圆形图标

RequestOptions options = new RequestOptions().circleCrop();

2.中心向外扩展的图片

.apply(new RequestOptions().centerCrop())

添加占位图

.apply(placeholderOf(R.mipmap.ic_launcher))

想实现高斯模糊,圆角或者圆形

添加依赖

implementation 'jp.wasabeef:glide-transformations:4.0.1'
 //高斯模糊
        RequestOptions options = new RequestOptions()
                .apply(bitmapTransform(new BlurTransformation(15,1)))
                .placeholder(R.mipmap.ic_launcher);

        Glide.with(this).load(urls[2]).apply(options).into(img4);

如果想实现两种效果,比如高斯模糊+圆角

  //同时要有两个效果
        MultiTransformation<android.graphics.Bitmap> multiTransformation = new MultiTransformation<>(
                new BlurTransformation(15, 1),
                new RoundedCorners(10)
        );
        //高斯模糊
        RequestOptions options = new RequestOptions()
                .apply(bitmapTransform(multiTransformation))
                .placeholder(R.mipmap.ic_launcher);

        Glide.with(this).load(urls[2]).apply(options).into(img4);

如果想对图片进行压缩,可以配合阿里oss图片使用

具体使用的话参考https://help.aliyun.com/document_detail/44686.html?spm=a2c4g.11186623.6.1409.776b56d8ounLbn

 意思是压缩到原先的30%,可以用于加载小图片节省资源

String url = url + "?x-oss-process=image/resize,p_30"

 

 

 

 

 

 

 

 

 

 

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值