rive-app / rive-android

A runtime for interactive animations on Android
https://rive.app
MIT License
332 stars 30 forks source link

Screenshot RiveAnimationView all transparent #288

Closed flipnovidade closed 11 months ago

flipnovidade commented 1 year ago

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
    }

'app.rive:rive-android:4.0.0'

Android minSdk 24 targetSdk 33

umberto-sonnino commented 1 year ago

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.