rive-app/rive-android

Screenshot RiveAnimationView all transparent

Closed this issue · 1 comments

Screenshot RiveAnimationView all transparent

I would like to take a screenshot of my view (RiveAnimationView).
I tried to use the pause and stop before the screenshot, but it didn't work.
The screenshot always show transparent.

I tested it with different views and the bitmap is always generated.

private val avatarView by lazy(LazyThreadSafetyMode.NONE) { binding.avatar }
val bitmap = avatarView.drawToBitmap()

    fun View.drawToBitmap(config: Bitmap.Config = Bitmap.Config.ARGB_8888): Bitmap {
        if (!ViewCompat.isLaidOut(this)) {
            throw IllegalStateException("View needs to be laid out before calling drawToBitmap()")
        }

        val bitmap =  Bitmap.createBitmap(width, height, config).applyCanvas {
            translate(-scrollX.toFloat(), -scrollY.toFloat())
            draw(this)
        }
        return bitmap
    }
  • Device: Android Emulator, Pixel 4

'app.rive:rive-android:4.0.0'

Android
minSdk 24
targetSdk 33

Hi @flipnovidade, can you send us a complete minimal repro (e.g. a github repo with an example app)?

Also, you might want to try upgrading the runtime version as we're currently on version 4.3.2.