参考:
http://www.jianshu.com/p/7610bdbbad17
https://github.com/bumptech/glide
https://futurestud.io/tutorials/glide-getting-started
https://mrfu.me/2016/02/28/Glide_Customize_Glide_with_Modules/
http://www.licheedev.com/2015/09/19/custom-glide-modelloader/
http://www.jianshu.com/p/31c82862ef19
1.自定义ModelLoader
classMyFileLoaderextendsStreamFileLoader {
@Override
publicDataFetcher getResourceFetcher(File model,intwidth,intheight) {
//在此做自定义格式转换
//TODO: 注意此处是主线程运行,不能做耗时操作
return super.getResourceFetcher(model, width, height);
}
publicMyFileLoader(Context context) {
super(context);
}
publicMyFileLoader(ModelLoader uriLoader) {
super(uriLoader);
}
}
2. 使用自定义ModelLoader
String path2 = Environment.getExternalStorageDirectory() + File.separator+"/2.webp";
Glide.with(context)
.using(newMyFileLoader(this))
.load(newFile(path2))//可以直接从file或者Uri加载
// .load("http://www1.zj.com/member/news_pic/2010-01-29/20100129141608426.jpg")
.placeholder(R.drawable.ic_launcher)//占位图(下载缓慢时显示)
.error(R.drawable.ic_launcher)//出错时要显示的图片
.crossFade()//淡入淡出的效果
.into(imageView1);