图片加载开源库学习笔记(好记性不如烂笔头) picasso: 1.picasso.load -> RequestCreator -> Dispatcher ->BitmapHunter(Runnable) 2.Dispatcher:HandlerThread进行消息管理 PicassoExecutorService(DEFAULT_THREAD_COUNT 3) 3.Cache key: Utils.createKey -> uri、size 4.okhttp: NetworkRequestHandler.load -> OkhttpDownloader.load(本地 FileRequestHandler) 5.避免重复加载:Dispatcher -> performSubmit -> hunterMap(key) UIL: 1.ImageLoader.getInstance.displayImage -> ImageLoaderEngine -> LoadAndDisplayImageTask(Runnable) 2.ImageLoaderConfiguration: memoryCache、diskCache、 DEFAULT_THREAD_POOL_SIZE 3 3.DisplayImageOptions: cacheInMemory、cacheOnDisk、showStubImage、showImageOnLoading、showImageForEmptyUri、showImageOnFail、imageScaleType、displayer、RoundedBitmapDisplayer 4.Cache key: MemoryCacheUtils.generateKey -> uri、size 5.HttpURLConnection: BaseImageDownloader.getStream -> getStreamFromNetwork(本地 getStreamFromFile) 6.避免重复加载: LoadAndDisplayImageTask -> run -> checkTaskNotActual -> isViewReused -> memoryCacheKey比较(ImageLoaderEngine.cacheKeysForImageAwares) 初步小结: 1.设计方面UIL只支持单例模式,相对于非单例模式来说,优点是共用节约内存,而缺点是不便销毁;Picasso两种模式均支持 2.在避免重复加载方面,picasso在task加入线程池前进行判重(同uri时任务合并,view复用时取消旧任务),而UIL在task开始执行的时候进行判重(view复用时当前旧任务提前结束),这块picasso稍优于UIL 3.UIL支持disk cache 4.网络方面picasso使用了okhttp 5.二者对使用列表的桌面插件支持都不完善