Created
September 6, 2017 21:24
-
-
Save Tom-Ski/d8b0be1c8b19cc735e5404c93c2e70a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public FileHandle saveFrameBuffer (FrameBuffer frameBuffer) { | |
FileHandle handle = Gdx.files.external("myscreenshot.png"); | |
frameBuffer.bind(); | |
Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Pixmap.Format.RGBA8888); | |
ByteBuffer pixels = pixmap.getPixels(); | |
Gdx.gl.glReadPixels(0, 0, frameBuffer.getWidth(), frameBuffer.getHeight(), GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels); | |
try { | |
PixmapIO.PNG writer = new PixmapIO.PNG((int)(pixmap.getWidth() * pixmap.getHeight() * 1.5f)); // Guess at deflated size. | |
try { | |
writer.setFlipY(true); | |
writer.write(handle, pixmap); | |
} finally { | |
writer.dispose(); | |
} | |
} catch (IOException ex) { | |
throw new GdxRuntimeException("Error writing PNG: " + handle, ex); | |
} | |
frameBuffer.dispose(); | |
pixmap.dispose(); | |
return handle; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment