Home » Android » android – Get Bitmap from TextureView efficiently

android – Get Bitmap from TextureView efficiently

Posted by: admin May 14, 2020 Leave a comment


I am trying to get each frame from a TextureView, unfortunately trying:


Results in slow performance is there a faster way to obtain a bitmap. Is it better to use the NDK instead?

Looking for actual examples

How to&Answers:

A TextureView receives frames on a SurfaceTexture, which takes frames sent to its Surface and converts them to a GLES texture. To get the pixel data out, the texture must be rendered to a framebuffer, then read out with glReadPixels(). The pixel data can then be wrapped with a Bitmap object (which may or may not involve copying the pixel data).

Using the NDK isn’t going to do you much good, as all of the code that needs to run quickly is already implemented natively.

You may see some improvement by sending the data directly to a SurfaceTexture and doing the GLES work yourself, but presumably you want to display the incoming frames in the TextureView, so all you’d potentially save is the Bitmap overhead (which may or may not be significant).

It might help if you explained in your question where the frames are coming from and what it is you want to do with them.