android開發使用Glide加載圖片模糊不清的解決方法


fun loadPreviewImage(context: Context, url: String, target: ImageView) {
val requestOptions = RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)  //關鍵代碼,加載原始大小
.format(DecodeFormat.PREFER_RGB_565)  //設置為這種格式去掉透明度通道,可以減少內存占有
.placeholder(R.drawable.img_error)
.error(R.drawable.img_error)
Glide.with(context)
.setDefaultRequestOptions(requestOptions)
.load(url)
.into(target)
}
針對於大圖,有個很好用的圖片顯示框架,使用的是Bitmap的分塊加載技術:https://github.com/davemorrissey/subsampling-scale-image-view
不過該庫結合使用Glide加載網絡圖片時,需要先使用Glide的downloadOnly把圖片下載到本地,再顯示,這樣才能發揮出分塊加載的性能優勢。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM