Libgdx之截图
Posted zqiang_55
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Libgdx之截图相关的知识,希望对你有一定的参考价值。
关于截图,官方的WIKI给了我们一个demo
public class ScreenShotTest extends ApplicationAdapter
Stage stage;
TextButton btn;
@Override
public void create()
stage = new Stage();
TextButton.TextButtonStyle style = new TextButton.TextButtonStyle();
style.font = new BitmapFont();
btn = new TextButton("JieTu", style);
btn.setPosition(100, 100);
btn.addListener(new ClickListener()
@Override
public void clicked(InputEvent event, float x, float y)
takeScreen();
);
stage.addActor(btn);
Gdx.input.setInputProcessor(stage);
@Override
public void render()
Gdx.gl.glClearColor(0.39f, 0.58f, 0.92f, 1.0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
@Override
public void dispose()
stage.dispose();
btn.getStyle().font.dispose();
private void takeScreen()
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();
Gdx.app.log("FY", "come here");
以上是关于Libgdx之截图的主要内容,如果未能解决你的问题,请参考以下文章