Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Bitmap from TextureView efficiently

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

textureView.getBitmap();

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

like image 329
AndyRoid Avatar asked Mar 27 '16 20:03

AndyRoid


1 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.

like image 159
fadden Avatar answered Oct 14 '22 09:10

fadden