The problem is that when you click, for example, on the display, a screenshot of the screen should be saved, but this does not happen, the image simply is not in the gallery or elsewhere, while if you test for the desktop version, the screen is successfully saved. I am making a drawing for android with saving work, but I do not know how else to save a picture on android.
if (Gdx.input.isTouched())
{
byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), true);
for (int i = 4; i < pixels.length; i += 4)
{
pixels[i - 1] = (byte) 255;
}
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.local("mypixmap.png"), pixmap);
local = Gdx.files.getExternalStoragePath().toString();
System.out.println(Gdx.files.getLocalStoragePath());
System.out.println(Gdx.files.getExternalStoragePath());
pixmap.dispose();
}
Gdx.files.local
is only for your internal files and can't be accessed by gallery.
You need to use Gdx.files.external
, but the current libGDX version uses a path here that is also not accessible under normal circumstances. It is changed for the next version .
Depending on what you want to achieve, there are other ways to get going with platform specific code.
androidx.core.content.FileProvider
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.