Glide 返回 Bitmap - Kotlin
Glide 版本:4.11.0
函数
/**
* 加载网络地址 [url] 图片返回 Bitmap
*/
fun load(url: String, success: (Bitmap) -> Unit) {
Glide.with(context) // context,可添加到参数中
.asBitmap()
.load(url)
.into(object : CustomTarget<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
// 成功返回 Bitmap
success.invoke(resource)
}
override fun onLoadCleared(placeholder: Drawable?) {
}
})
}
调用
load(url) { bitmap ->
// 得到 Bitmap
}
说明
SimpleTarget 已弃用,使用 CustomTargert
这篇博客详细介绍了如何在Kotlin中利用Glide库来获取并返回Bitmap对象,包括具体的函数调用和使用说明。


被折叠的 条评论
为什么被折叠?



