有效地从TextureView获取位图 [英] Get Bitmap from TextureView efficiently

查看:1227
本文介绍了有效地从TextureView获取位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从TextureView获取每个帧,不幸的是尝试:

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

textureView.getBitmap();

导致性能下降的原因是有一种更快的方法来获取位图.改用NDK更好吗?

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

寻找实际示例

推荐答案

TextureView在SurfaceTexture上接收帧,该帧将发送到其Surface的帧转换为GLES纹理.要取出像素数据,必须将纹理渲染到帧缓冲区,然后使用glReadPixels()读出.然后可以使用Bitmap对象包装该像素数据(该对象可能涉及复制像素数据,也可能不涉及复制像素数据).

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

使用NDK不会帮上大忙,因为所有需要快速运行的代码已经在本机实现.

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.

通过将数据直接发送到SurfaceTexture并自行完成GLES工作,您可能会看到一些改进,但是大概您希望在TextureView中显示传入的帧,因此,您可能节省的只是Bitmap开销(这可能或可能不重要).

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.

这篇关于有效地从TextureView获取位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆