为什么在Glide 4.9.0中使用.asBitmap()会崩溃

时间:2019-03-19 20:08:33

标签: crash android-glide

只需升级到Glide 4.9.0, 在kotlin扩展名ImageView.loadImg中,使用.asBitmap()会崩溃,但是如果没有.asBitmap(),它对于相同的imageUrl(在浏览器中可以正常加载图片)也可以正常工作

fun ImageView.loadImg(imageUrl: String) {
    var requestOptions : RequestOptions  = RequestOptions()
    requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL)
    requestOptions.error(R.mipmap.ic_launcher)
    if (!TextUtils.isEmpty(imageUrl)) {
        GlideApp.with(this.context)
            .setDefaultRequestOptions(requestOptions)
            .asBitmap()  //this one causes crash
            .load(imageUrl)
            .into(this)
    }
}

发生在调用customImageView?.loadImg(imageUrl)时,从AppCompatImageView派生的iamgeView的setImageBitmap()

class CustomImageView : AppCompatImageView {

    ... ...

    override fun setImageBitmap(bm: Bitmap) {//<== crash at here
        super.setImageBitmap(bm)
        bitmap = bm
    }
}

不使用.asBitmap()是否存在问题? 有什么主意吗?

0 个答案:

没有答案