关于截图,官方的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");
}
}