我正在尝试以最有效的方式截取屏幕截图。我认为使用 FrameBuffer 是截取屏幕截图的最有效方法,因为我可以在与渲染线程不同的线程中处理数据。 如何从 FrameBUffer 获取信息并将其传输到文件?
FrameBuffer m_fbo;
render(){
m_fbo = new FrameBuffer(Format.RGB565, (int)(w * m_fboScaler), (int)(h * m_fboScaler), false);
m_fboRegion = new TextureRegion(m_fbo.getColorBufferTexture());
m_fboRegion.flip(false, true);
m_fbo.begin();
...rendering...
m_fbo.end();
writeTextureRegionToFile(); - i need some lines of code for the implementation of this method
}
最佳答案
FrameBuffer
内容驻留在由 OpenGL 管理的内存中,因此您(据我所知)仍然需要在渲染线程上使用 OpenGL API 来获取这些字节。具体来说,您想要 the ScreenUtils
class
获取包含 FrameBuffer
的 RGBA8888
内容的 byte[]
。
当然,一旦获得原始字节,您就可以在不同的线程上进行任何压缩/转换/输出。有一个forum post它有一个快速而肮脏的 PNG writer。 Libgdx 特定的 (?) CIM
格式也是一个选项(请参阅 PixmapIO
class ),但您必须首先将字节转换为 Pixmap
。
关于file - FrameBuffer 到 libgdx 或 OpenGL 内的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15828879/