Glide添加自定義圖片格式支持

參考:

http://www.lxweimin.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.lxweimin.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);

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容