2
我试图做一个截图保护程序例程。我正在使用的代码here作为基础,因此产生的代码是这样的:截图例程给出一个LibGdx空白图像
public void update(float deltaTime) {
if(Gdx.input.isKeyPressed(Keys.ESCAPE)) {
Gdx.app.exit();
}
if(Gdx.input.isKeyPressed(Keys.F10)) {
this.saveScreenshot(new FileHandle(new File("screenshots/screenShot001.png")));
}
}
public void saveScreenshot(FileHandle file) {
Pixmap pixmap = getScreenshot(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
PixmapIO.writePNG(file, pixmap);
pixmap.dispose();
}
public Pixmap getScreenshot(int x, int y, int w, int h, boolean flipY) {
Gdx.gl.glPixelStorei(GL10.GL_PACK_ALIGNMENT, 1);
final Pixmap pixmap = new Pixmap(w, h, Format.RGBA8888);
ByteBuffer pixels = pixmap.getPixels();
Gdx.gl.glReadPixels(x, y, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixels);
final int numBytes = w * h * 4;
byte[] lines = new byte[numBytes];
if (flipY) {
final int numBytesPerLine = w * 4;
for (int i = 0; i < h; i++) {
pixels.position((h - i - 1) * numBytesPerLine);
pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
}
pixels.clear();
pixels.put(lines);
} else {
pixels.clear();
pixels.get(lines);
}
return pixmap;
}
的文件被创建,它似乎是一个正确的尺寸正确的PNG图像,但它是一个空白的。该应用程序是setup-ui制作的示例,并显示libGDX徽标。任何想法的问题?
你还在某处呈现标志吗? (), – noone
是的,我在我的渲染方法渲染标志@Override \t public void render(){ \t \t Gdx.gl.gl.glClearColor(1,1,1,1); \t \t Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); \t \t controller.update(Gdx.graphics.getDeltaTime()); \t \t batch.setProjectionMatrix(camera.combined); \t \t batch.begin(); \t \t sprite.draw(batch);batch.end(); \t} – Killrazor