如何在 LibGDX 中保存和检索图像文件。我想在 AndroidApplication 类的本地存储中保存一个图像文件,并在我的核心项目中检索它。
最佳答案
Libgdx 中的文件处理在 libGDX wiki 中有很好的描述。 .
简而言之:您正在使用 FileHandle 对象打开文件,该对象可以通过调用其中之一来检索
Gdx.files.external("path.txt"); //files on SD card [Android]
Gdx.files.absolute("path.txt"); //absolute path to file
Gdx.files.internal("path.txt"); //asset directory
Gdx.files.local("path.txt"); //local storage - only here you can write safely!
然后从文件创建纹理看起来像
Texture tex = new Texture( Gdx.files.internal("path.jpg") );
那么您应该做的是使用external() 获取一个文件来检索FileHandle ,然后用它做任何你想做的事,然后使用 local() 保存它。 FileHandle 有方法 readBytes() 和 writeBytes 允许你打开/保存数据
FileHandle from = Gdx.files.external("image.jpg");
byte[] data = from.readBytes();
...
FileHandle to = Gdx.files.local("image.jpg");
to.writeBytes(data);
关于java - 在 LibGDX 中保存和检索图像文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32816723/