zebleckDAMM
zebleckDAMM

Reputation: 333

How do you save the rendering of a tiled map to an image?

im currently using LibGDX and drawing a tiledmap with the OrthogonalTiledMapRenderer. Is there a way to save one rendering and put it into some file as an image? If you know of a method that doesnt use OrthogonalTiledMapRenderer, thats ok too.

Upvotes: 0

Views: 97

Answers (1)

PiotrJ
PiotrJ

Reputation: 151

Simplest way would be to take a screenshot of the screen. Do this after you draw the map with the renderer:

byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), true);

Pixmap pixmap = new Pixmap(Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888);
BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
PixmapIO.writePNG(Gdx.files.external("mypixmap.png"), pixmap);
pixmap.dispose();

Taken from the wiki: https://github.com/libgdx/libgdx/wiki/Taking-a-Screenshot

If you need something fancier, take a look at ScreenUtils#getFrameBufferPixels source code.

Upvotes: 1

Related Questions