Created
July 2, 2016 07:06
-
-
Save wuapnjie/f36b27250617ec0fbd039851fed0f452 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ImagePipelineConfig getImagePipelineConfig() { | |
ImagePipelineConfig config = ImagePipelineConfig.newBuilder(App.getAppContext()) | |
.setWebpSupportEnabled(true) | |
/** | |
* 必须和ImageRequest的ResizeOptions一起使用,作用就是在图片解码时根据ResizeOptions所设的宽高的像素进行解码,这样解码出来可以得到一个更小的Bitmap。ResizeOptions和DownsampleEnabled参数都不影响原图片的大小,影响的是EncodeImage的大小,进而影响Decode出来的Bitmap的大小,ResizeOptions须和此参数结合使用是因为单独使用ResizeOptions的话只支持JPEG图,所以需支持png、jpg、webp需要先设置此参数。 | |
*/ | |
.setDownsampleEnabled(true) | |
/** | |
* 最终影响的是mDownsampleEnabledForNetwork参数。 这个参数的作用是在mDownsampleEnabled为true的情况下,设置是否当这次请求是从网络中加载图片时,来对三级缓存中的编码图片重新改变大小。 | |
*/ | |
.setResizeAndRotateEnabledForNetwork(true) | |
/** | |
* 是否根据不同的平台来构建相应的解码器 | |
*/ | |
.setDecodeMemoryFileEnabled(true) | |
/** | |
* 所加载图片的配置,默认为Bitmap.Config.ARGB_8888 | |
*/ | |
.setBitmapsConfig(Bitmap.Config config) | |
/** | |
* 三级缓存中已解码图片的内存缓存配置 | |
*/ | |
.setBitmapMemoryCacheParamsSupplier(bitmapCacheParamsSupplier) | |
/** | |
* 三级缓存中编码图片的内存缓存 | |
*/ | |
.setEncodedMemoryCacheParamsSupplier(encodedCacheParamsSupplier) | |
/** | |
* 三级缓存中硬盘缓存的配置,默认缓存目录在app自身CacheDir的image_cache目录下 | |
*/ | |
.setMainDiskCacheConfig(mainDiskCacheConfig) | |
/** | |
* 执行各个任务的线程池配置,包括配置执行IO任务、后台任务、优先级低的后台任务、Decode任务的线程池的配置。 | |
*/ | |
.setExecutorSupplier(executorSupplier) | |
/** | |
* 缓存的统计数据追踪器。它是一个接口,提供了各个缓存中图片Hit与Miss的回调方法,通常可以使用它来统计缓存命中率 | |
*/ | |
.setImageCacheStatsTracker(imageCacheStatsTracker) | |
/** | |
* 注册一个内存调节器,它将根据不同的MemoryTrimType回收类型在需要降低内存使用时候进行回收一些内存缓存资源(Bitmap和Encode)。数值越大,表示要回收的资源越多。 | |
*/ | |
.setMemoryTrimmableRegistry(memoryTrimmableRegistry) | |
/** | |
* 网络图片下载请求类 | |
*/ | |
.setNetworkFetchProducer(networkFetchProducer) | |
/** | |
* 渐进式显示网络的JPEG图的配置,不过要使用渐进式显示图片,需要在ImageRequest中显示的设置是否支持渐进式显示:setProgressiveRenderingEnabled(true) | |
*/ | |
.setProgressiveJpegConfig(progressiveJpegConfig) | |
/** | |
* 小图的硬盘缓存配置,默认是和主硬盘缓存目录是共用的。如果需要把小图和普通图片分开,则需重新配置。 | |
*/ | |
.setSmallImageDiskCacheConfig(smallImageDiskCacheConfig) | |
.build(); | |
return config; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment