Copy from one surface to another surface

1.2k Views Asked by At

I currently have two different surfaces (one from SurfaceView and another surface created from MediaCodec).

What are the different ways available to copy from one surface to another?

1

There are 1 best solutions below

11
dev.bmax On

In the Android graphics architecture a Surface plays the role of a consumer of buffers containing the graphical data (e.g. video frames).

A typical consumer does not provide access to the buffers that it holds. An exception is the special type ImageReader that allows direct application access to image data rendered into its Surface.

There is a less efficient way to copy the contents of a SurfaceView into a Bitmap using PixelCopy. While TextureView allows you to get the Bitmap directly.

You can then draw the Bitmap image onto another Surface using its Canvas.

Links:

https://source.android.com/devices/graphics/arch-sh

https://developer.android.com/reference/android/media/ImageReader

https://developer.android.com/reference/android/view/PixelCopy

https://developer.android.com/reference/android/view/Surface#lockCanvas(android.graphics.Rect)

https://developer.android.com/reference/android/graphics/Canvas#drawBitmap(android.graphics.Bitmap,%20android.graphics.Rect,%20android.graphics.Rect,%20android.graphics.Paint)