asBitmap().format(DecodeFormat.PREFER_ARGB_8888) not working
Glide Version: 3.7.0 Integration libraries: okhttp3-integration-1.4.0 Device/Android Version: Nexus 5X
I want to set PREFER_ARGB_8888 for some specific cases but it does not work somehow.
fun loadCrossfadeCropCenter(view: ImageView,
url: String?,
rounded: Boolean = false,
placeholder: Int? = null,
betterQuality: Boolean = true) {
if (url == null) return
Glide.clear(view)
val requestBuilder = Glide.with(view.context).load(url)
if (betterQuality) {
requestBuilder.asBitmap().format(DecodeFormat.PREFER_ARGB_8888)
}
requestBuilder
.animate(R.anim.abc_fade_in) // replace .crossFade()
.centerCrop()
if (placeholder != null) {
requestBuilder
.placeholder(placeholder)
.error(placeholder)
.into(ViewTarget(view, rounded) as Target<GlideDrawable>)
} else {
requestBuilder
.into(ViewTarget(view, rounded) as Target<GlideDrawable>)
}
}
When I use the global configuration then it works
override fun applyOptions(context: Context, builder: GlideBuilder) {
// Apply options to the builder here.
builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888)
}
Do you have any idea?
requestBuilder.asBitmap() returns a new builder with different type arguments, you have to continue calling other builder methods (especially into()) on that object.
Btw, Glide 3.8.0 will have .asBitmap().crossFade(), you can try the snapshot.
@TWiStErRob Is it okay to use a snapshot version of Glide in a production app?
@idish that really depends on your team/company. I use 3.8.0-SNAPSHOT in a personal published app, there are very rare commits to that one, pretty much waiting to be released. 3.7.0->3.8.0 increase guarantees backwards compatibility; however 3.7.0->4.0 doesn't and even the 4.0.0-SNAPSHOTs may contain breaking changes, because it's unreleased yet. You can simulate .asBitmap().crossFade() in an earlier version though, see #840