已知使用Glide图片加载框架加载图片时会自动通过某种方法加载图片到内存,而自己加载大图则需要收到更改BitmapFactory.Options的值来使用图片,那么我们可以通过Glide来加载图片简化过程,代码如下
Glide.with(this)
.asBitmap()
.load(R.drawable.ftp_bg)
.into(object : CustomTarget<Bitmap>() {
override fun onLoadCleared(placeholder: Drawable?) {
//这里应该是使用占位图
}
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
val drawable = BitmapDrawable(resource)
top_layout.background = drawable
}
})