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