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