'Blur imageView in Android
I am using the method answered in this thread I implemented the dependencies into build.gradle but when I paste the code it shows me errors that I don't have class name Glide. How do I work around this so I can make my ImageView blur?
I have simple code for learning purposes
imageView4.setOnClickListener {
if (!haveImage) {
Toast.makeText(this, "Image not imported yet!", Toast.LENGTH_LONG).show()
} else {
val imgUri = Uri.parse("android.resource://com.example.myapplication/" + R.drawable.ic_launcher)
imageView4.setImageURI(imgUri)
}
}
Solution 1:[1]
Make sure to specify Glide in gradle like this
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'jp.wasabeef:glide-transformations:4.1.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
Apply the transformation
Glide.with(this@MainActivity)
.asBitmap()
.load(R.drawable.ic_launcher)
.apply(RequestOptions.bitmapTransform(BlurTransformation(25, 3)))
.into(imageView)
Solution 2:[2]
With the new Android API Level 31 (Android 12) you can use method android.view.View#setRenderEffect() to apply blur effect to a view:
imageView.setRenderEffect(
RenderEffect.createBlurEffect(
20.0f, 20.0f, Shader.TileMode.CLAMP
)
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | BigSt |
