如何在 LibGDX 中保存和检索图像文件。我想将图像文件保存在 AndroidApplication 类的本地存储中,并在我的 Core 项目中检索它。
Libgdx 中的文件处理在libGDX 维基 https://github.com/libgdx/libgdx/wiki/File-handling.
简而言之:您正在使用 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") );
那么你应该做的是使用以下命令获取文件外部的()检索文件句柄 https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/files/FileHandle.html,然后用它做任何你想做的事情并使用保存它local()。 FileHandle 有方法读取字节() and 写入字节数允许您打开/保存数据
FileHandle from = Gdx.files.external("image.jpg");
byte[] data = from.readBytes();
...
FileHandle to = Gdx.files.local("image.jpg");
to.writeBytes(data);
如果你想在保存之前修改图像,你应该看看Pixmap https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Pixmap.html and PixmapIO https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/PixmapIO.html classes
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)