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
}
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.
'app.rive:rive-android:4.0.0'
Android minSdk 24 targetSdk 33