android開發使用Glide加載Bitmap的方法


方法一:不推薦,會出現閃爍
fun loadBitmapImage(target: ImageView, bitmap: Bitmap) {
val baos = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos)
val bytes: ByteArray = baos.toByteArray()
val requestOptions = RequestOptions().centerCrop()
Glide.with(target.context)
.setDefaultRequestOptions(requestOptions)
.load(bytes)
.into(target)
baos.closeQuietly()
}

方法二:推薦
fun loadBitmapImage(target: ImageView, bitmap: Bitmap) { val drawable
= BitmapDrawable(target.resources, bitmap) val requestOptions = RequestOptions().centerCrop() .diskCacheStrategy(DiskCacheStrategy.ALL) .error(drawable)  //放在出錯位置 .placeholder(drawable)  //放在占位符位置 Glide.with(target.context) .setDefaultRequestOptions(requestOptions) .load("https://${System.currentTimeMillis()}")  //隨便給個不可用的url .into(target) }

 


免責聲明!

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



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