'How do you extract the underlying Bitmap from an ImageView with RenderEffect?

I've been looking into applying blur to a Bitmap via ImageView using RenderEffect. I'm able to do so through setRenderEffect. However, when I try to get Bitmap out of the ImageView,  using the below (hacky) code, it does not have the blur applied to it. I believe this is because the layer is applied but not to the underlying bitmap in the ImageView (not 100% certain). This leads me to the question of: how do you get the underlying Bitmap associated with an ImageView that is rendered on the screen after RenderEffect has been applied?

        val testImageView = ImageView(applicationContext)
        testImageView.setImageBitmap(someBitmap)
        val blurEffect = RenderEffect.createBlurEffect(30.0f, 30.0f, Shader.TileMode.MIRROR)
        testImageView.setRenderEffect(blurEffect)
        testImageView.invalidate()
        val testDrawable = testImageView.drawable as BitmapDrawable
        val testBitmap = testDrawable.getBitmap(); // This doesn't have Blur applied to it even though I'd like it to.

Using RenderScript looks possible but it's been deprecated past API 31, so I've been looking for an alternative.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source