1

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)
      }
 }
kenny_k
  • 3,831
  • 5
  • 30
  • 41
Ecodor
  • 27
  • 8

2 Answers2

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)
Simon
  • 1,657
  • 11
  • 16
  • It shows error for 'BlurTransformations' (create abstract function 'BlurTransf...'), also 'setImageURI' doesn't work anymore. Could you please give more in-depth answer? Thanks alot! – Ecodor Oct 08 '19 at 11:35
  • You need another gradle dependency. Add glide-transformations and it should work. – Simon Oct 08 '19 at 11:42
  • BOOM that fixes the problem, i am sorry for the earlier comment about the 'setImageURI' it was my mistake in the xml file :))) – Ecodor Oct 08 '19 at 11:51
0

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
    )
)
Sergio
  • 27,326
  • 8
  • 128
  • 149