android 高级之旅 (三 )picasso、glide、imageloader等几个常用的图片加载框架
来源:互联网 发布:淘宝店怎么经营管理 编辑:程序博客网 时间:2024/05/22 11:25
现在网络上的图片加载库已经多如牛毛了,所以选择一个适合自己的图片加载库是非常有助于项目开发的。
现在几个被用的比较多的库有:UIL,Picasso, Glide, ImageLoader, Volley 和 Fresco。
如下简介:
Universal Image Loader:一个强大的图片加载库,包含各种各样的配置,最老牌,使用也最广泛。只可惜作者已经停止该项目的维护了,所以不太推荐使用。
Picasso:Square出品,和OkHttp搭配使用效果简直杠杠滴。主要特点就是使用简单,扩展性强,支持各种来源的图片,包括网络、Resources、assets、files、content providers等。内部集成了OkHttp的网络框架,所以如果你的项目中使用了Square公司的其他框架,那么推荐使用Picasso,兼容性会好一些。
Volley :Google官方出品,详细移步这里
Fresco:Facebook出的,就我看来,除非你的项目有非常多图片展示的模块,慎用,但用好了,还是非常不错的。
Glide:Google推荐的图片加载库,专注于流畅的滚动。代码风格与Picasso非常相似,增加了更多的功能,非常重要的就是支持gif,当然它的包会大一些。如果你的项目对图片的使用场景非常多,并且需要支持gif,则推荐使用。
今天我们就说 Picasso ImageLoader Glide 三个库。
一 、 picasso
特点
1 提供内存和磁盘缓存,默认开启,可以设置不进行缓存
2 图片加载过程中默认显示的图片
3 图片加载失败或出错后显示的图片
4 图片加载成功或失败的回调
5 自定义图片大小、自动测量ImageView大小、裁剪、旋转图片等
6 对图片进行转换
7 标签管理,暂停和恢复图片加载
8 请求优先级管理
9 可以从不同来源加载图片,网络、Resources、assets、files、content providers
10 更加丰富的扩展功能
添加:
compile 'com.squareup.picasso:picasso:2.5.2'picasso基本的使用及API相当简单,说只需要一行代码就能满足你也不为过Picasso.with(this).load(imageUrl).into(imageView);
常用API也不多 如下:
Picasso.with(this) .load(url) .centerCrop() .error() .resize() .into(iv);
一般项目中的图片异步加载需求,picasso完全可以满足需求。
二、Imageloader
算了,相对于其他几个库来说,imageloader已经可以淘汰了,我就不再多说,想了解的同学 移步这里
三、 Glide
Glide 使用与picasso大同小异,使用这些库基本上是一法通万法通,api也很好理解。但欲钻研其原理底层之类的还是需要仔细研究。
转自这里 glide更多点击这里
网络加载图片
Glide.with(context).load(internetUrl).into(targetImageView);
从文件加载
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"Test.jpg");Glide.with(context).load(file).into(imageViewFile);
从资源id
int resourceId = R.mipmap.ic_launcher;Glide.with(context).load(resourceId).into(imageViewResource);
从uri
Glide.with(context).load(uri).into(imageViewUri);
加载gif
String gifUrl = "xxxxx";Glide.with( context ).load( gifUrl ).into( imageViewGif );
一些常规方法(待加载时显示,加载出错时显示)
Glide.with( context ).load( gifUrl ).placeholder( R.drawable.cupcake ).error( R.drawable.full_cake ).into( imageViewGif );
强制转化为gif
Glide.with( context ).load( gifUrl ).asGif().error( R.drawable.full_cake ).into( imageViewGif );
用bitMap播放Gif
Glide.with( context ).load( gifUrl ).asBitmap().into( imageViewGifAsBitmap );
播放本地mp4,只能是本地
String filePath = "/storage/emulated/0/Pictures/example_video.mp4";Glide.with( context ).load( Uri.fromFile( **new **File( filePath ) ) ).into( imageViewGifAsBitmap );
实现圆形图片
Glide.with(this).load(ur2).asBitmap().centerCrop().into(new BitmapImageViewTarget(iv){ @Override protected void setResource(Bitmap resource) { super.setResource(resource); RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getApplicationContext().getResources(), resource); circularBitmapDrawable.setCircular(true); iv.setImageDrawable(circularBitmapDrawable); } });
- android 高级之旅 (三 )picasso、glide、imageloader等几个常用的图片加载框架
- 图片加载的框架 Imageloader Picasso Glide
- Android图片加载与缓存开源框架总结七部曲:Glide Picasso ImageLoader Fresco ASimpleCache等
- Android图片加载框架:ImageLoader,Volley,Picasso,Glide,Fresco
- Android图片加载框架:ImageLoader,Volley,Picasso,Glide,Fresco
- Android图片加载框架分析之Glide、Picasso和Fresco
- 图片加载框架Glide,Picasso fresco volley imageloader Universal Image Loader的比较
- Android万能的图片加载框架(Glide、Fresco、Picasso)
- 常用的图片处理框架UIL、Picasso、Glide、Fresco、Volley ImageLoader比较分析
- 图片加载三方库ImageLoader,Fresco,Picasso,Glide
- Android图片加载框架(universal-image-loader,Picasso,Glide,Fresco)的用法
- 主流图片加载框架ImageLoader、Glide、Picasso、Fresco性能分析---图片加载速度比较
- 主流图片加载框架ImageLoader、Glide、Picasso、Fresco性能分析---内存占用比较
- Android图片加载框架比较----Glide,Picasso,Fresco
- android图片加载框架比较----Glide,Picasso,Fresco
- Android图片加载框架比较----Glide,Picasso,Fresco
- Android图片加载框架——Picasso和Glide
- Android图片加载框架——Picasso和Glide
- JS组件系列——表格组件神器:bootstrap table(三:终结篇,最后的干货福利)
- bzoj 3029: 守卫者的挑战 概率dp
- cordova app 升级
- 简易拼图(OC)
- 软件工程(C编码实践篇)学习总结
- android 高级之旅 (三 )picasso、glide、imageloader等几个常用的图片加载框架
- Web服务器的工作原理
- Inno Setup使用方法备份
- hdoj 1090
- 21款生物信息在线分析工具汇编
- Excel中利用OFFSET函数解决很多个分块的一次性转置问题(非纯手动)
- 深度序列化的一种解决方案
- Python学习笔记1
- 如何安装centos系统