我创建了一个游戏,其中有一个按钮,点击时会拍摄一个屏幕截图。
ChangeListener changeListener = new ChangeListener() {
//take screenshot and share
if(actor.equals(shareBtn)){
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("screenShot.png"), pixmap);
pixmap.dispose();
}
};
当我在电脑上运行游戏时没有问题,但是当我在Android上运行它时我得到了这个错误(我的手机有一个外置SD卡)。
com.badlogic.gdx.utils.GdxRuntimeException: Error writing file: screenShot.png (External)
Caused by: java.io.FileNotFoundException: /storage/emulated/0/screenShot.png: open failed: EACCES (Permission denied)
答案 0 :(得分:1)
如果您要定位Android SDK< 23,请确保您已添加了在清单文件中写入外部存储的权限。否则,请在运行时获取权限。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>