Take Screenshot of SurfaceView

The SurfaceView’s surface is independent of the surface on which View elements are drawn. So capturing the View contents won’t include the SurfaceView.

You need to capture the SurfaceView contents separately and perform your own composition step. The easiest way to do the capture is probably to just re-render the contents, but use an off-screen bitmap as the target rather than the surface. If you’re rendering with GLES to an off-screen pbuffer, you can use glReadPixels() before you swap buffers.

Update: Grafika’s “texture from camera” activity demonstrates handling live video from the camera with OpenGL ES. EglSurfaceBase#saveFrame() shows how to capture GLES rendering to a Bitmap.

Update: See also this answer, which provides a bit more background.

Leave a Comment