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) }
原文地址:https://www.cnblogs.com/yongfengnice/p/13488858.html