Search in sources :

Example 1 with PNG

use of com.badlogic.gdx.graphics.PixmapIO.PNG in project libgdx by libgdx.

the class PngTest method render.

public void render() {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    if (screenshot == null) {
        int width = Gdx.graphics.getWidth(), height = Gdx.graphics.getHeight();
        for (int i = 0; i < 100; i++) batch.draw(badlogic, MathUtils.random(width), MathUtils.random(height));
        batch.flush();
        FileHandle file = FileHandle.tempFile("screenshot-");
        System.out.println(file.file().getAbsolutePath());
        Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        try {
            PNG writer = new PNG((int) (pixmap.getWidth() * pixmap.getHeight() * 1.5f));
            // writer.setCompression(Deflater.NO_COMPRESSION);
            writer.write(file, pixmap);
            // Write twice to make sure the object is reusable.
            writer.write(file, pixmap);
            writer.dispose();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        screenshot = new Texture(file);
    }
    batch.draw(screenshot, 0, 0);
    batch.end();
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) PNG(com.badlogic.gdx.graphics.PixmapIO.PNG) IOException(java.io.IOException) Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Aggregations

FileHandle (com.badlogic.gdx.files.FileHandle)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 PNG (com.badlogic.gdx.graphics.PixmapIO.PNG)1 Texture (com.badlogic.gdx.graphics.Texture)1 IOException (java.io.IOException)1