I am using Jetpack's GameActivity to render my game in Android, and I am adding some native views on the top of it in the Kotlin code. I would like a way to capture the entire screen as a Bitmap, but somehow the OpenGL rendered things do not appear on the saved Bitmap, just the "normal" Android View's.
This is how I am doing to capture the Bitmap:
private fun captureGameImage(v: View): Bitmap {
val b = Bitmap.createBitmap(v.width, v.height, Bitmap.Config.ARGB_8888)
val c = Canvas(b)
v.draw(c)
return b
}
on my onCreate
this is how I get the rootView
, which I later on send to this method. I inflate the overlay layout and add to it:
val overlayViews = layoutInflater.inflate(R.layout.widgets, null)
rootView = (findViewById<View>(android.R.id.content) as ViewGroup)
rootView.addView(overlayViews)
Then at some point I invoke:
captureGameImage(rootView)
Again, the created Bitmap has all the views that are on the overlayViews
, but the game itself is not there. I even debugged the captureGameImage
function and indeed the v
has two children views, the game one and the overlay one, but somehow the game one doesn't get captured in the Bitmap.
Any ideas how to capture the entire view, including the game rendered stuff?