首页 > 代码库 > 常用 Android 图片处理框架的比较

常用 Android 图片处理框架的比较

Fresco 12,324星星

https://github.com/facebook/fresco
FaceBook出品,支持Android 2.3 (Gingerbread)及以上
尼玛,他竟然有专门的中文文档:https://www.fresco-cn.org/docs/index.html

添加依赖
  1. //添加依赖
  2. compile ‘com.facebook.fresco:fresco:1.2.0‘

  3. //**************下面的依赖需要根据需求添加******************//
  4. // 在 API < 14 上的机器支持 WebP 时,需要添加
  5. compile ‘com.facebook.fresco:animated-base-support:1.2.0‘
  6. // 支持 GIF 动图,需要添加
  7. compile ‘com.facebook.fresco:animated-gif:1.2.0‘
  8. // 支持 WebP (静态图+动图),需要添加
  9. compile ‘com.facebook.fresco:animated-webp:1.2.0‘
  10. compile ‘com.facebook.fresco:webpsupport:1.2.0‘
  11. // 仅支持 WebP 静态图,需要添加
  12. compile ‘com.facebook.fresco:webpsupport:1.2.0‘

GitHub上的介绍:
Fresco is a powerful system for displaying images in Android applications.

Fresco takes care of image loading and display, so you don‘t have to. It will load images from the network, local storage, or local resources, and display a placeholder占位符 until the image has arrived. It has two levels of cache; one in memory and another in internal storage.

In Android 4.x and lower, Fresco puts images in a special region of Android memory. This lets your application run faster - and suffer the dreaded OutOfMemoryError much less often.

Fresco also supports:
  • streaming of progressive JPEGs
  • display of animated GIFs and WebPs
  • extensive广阔的 customization of image loading and display
  • and much more!

Fresco 支持许多URI格式,但 Fresco 不支持 相对路径的URI。所有的 URI 都必须是绝对路径,并且带上该 URI 的 scheme。如下:
类型                         SCHEME     示例
远程图片                 http://     HttpURLConnection 或者参考 使用其他网络加载方案
本地文件                 file://     FileInputStream
ContentProvider content://    ContentResolver
asset目录下的资源 asset://     AssetManager
res目录下的资源 res://     Resources.openRawResource
Uri中指定图片数据 data:mime/type;base64     数据类型必须符合 rfc2397规定 (仅支持 UTF-8)

总结
  • 优点:支持图像渐进式呈现,大公司出品,后期维护有保障
  • 缺点:框架体积较大,3M左右会增大apk的大小;操作方式不是特别简单,有一定学习成本
  • 特点:有两级内存一级文件的缓存机制,并且有自己特别的内存区域来处理缓存,避免oom

Glide 14,408星星

https://github.com/bumptech/glide
谷歌员工出品,Google推荐的图片加载库,专注于流畅的滚动

添加依赖
  1. repositories {
  2. mavenCentral() // jcenter() works as well because it pulls from Maven Central
  3. }
  4. dependencies {
  5. compile ‘com.github.bumptech.glide:glide:3.7.0‘
  6. compile ‘com.android.support:support-v4:19.1.0‘
  7. }

GitHub上的介绍:
An image loading and caching library for Android focused on smooth scrolling

Glide is a fast and efficient open source media management and image loading framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.

Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs. Glide includes a flexible API that allows developers to plug in to almost any network stack. By default Glide uses a custom HttpUrlConnection based stack, but also includes utility libraries plug in to Google‘s Volley project or Square‘s OkHttp library instead.

Glide‘s primary首要的 focus is on making scrolling any kind of a list of images as smooth and fast as possible, but Glide is also effective for almost any case where you need to fetch, resize, and display a remote image.

总结
  • 优点:加载速度极快,框架体积小,四五百KB
  • 缺点:因为机制的选择不同,速度快了,但是图片质量低了,RGB565
  • 特点:根据ImageView大小来进行缓存,也就是说一张图片可能根据展示情况来缓存不同尺寸的几份

Picasso 13,035星星

https://github.com/square/picasso 
Square出品,算是一个出来时间比较长的框架了

添加依赖
  1. compile ‘com.squareup.picasso:picasso:2.5.2‘

GitHub上的介绍就一句话:
A powerful image downloading and caching library for Android

优点:图片质量高
缺点:加载速度一般
特点:只缓存一个全尺寸的图片,根据需求的大小在压缩转换

Universal-Image-Loader 15,053星星

https://github.com/nostra13/Android-Universal-Image-Loader 
尼玛,这个虽然最近基本更新了,而且还不提供Gradle的支持,但依然是星星最多的一个图片处理库

jar包下载
Powerful and flexible library for loading, caching and displaying images on Android.

优点:丰富的配置选项
缺点:最近一次维护在15年底,后期有不维护的趋势,可能被当前图片框架替代
特点:三级缓存的策略

总结:如果对图片质量要求不是太高的话,个人推荐Glide,其次推荐Fresco


null


常用 Android 图片处理框架的比较