2

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();
}
zackscript
  • 35
  • 5
  • I also added permissions to the minifest: – zackscript Aug 19 '20 at 14:12
  • Local files are private to your app. External should be used for screenshots that you want to be available outside the game. To save them to the actual gallery, I don't think LibGDX provides a direct way. You may have to write your own code to write the file (https://stackoverflow.com/questions/8560501/android-save-image-into-gallery), and access it from your `core` module using a platform resolver interface (https://github.com/libgdx/libgdx/wiki/Interfacing-with-platform-specific-code) – Tenfour04 Aug 19 '20 at 14:23

1 Answers1

0

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.

  • Do you want to save screenshots periodically? Use app-specific storage from 1.9.12
  • Do you want to share the screenshot to another app? Use local storage and androidx.core.content.FileProvider
  • Do you want to open a dialog and the user can save the image? Use Storage Access Framework
MrStahlfelge
  • 1,721
  • 2
  • 13
  • 23