我知道有很多与这个问题相关的问题,但似乎很少有关于 openGL 的。
我正在尝试将一些 PNG 文件从 assets 文件夹加载到位图中,但由于某种原因,返回的位图为 null,这又会在此处抛出 NullPointerException:
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
我用来从 Assets 文件夹加载图像的代码:
public static Bitmap getBitmapFromAsset(AssetManager mgr, String path)
{
InputStream is = null;
Bitmap bitmap = null;
try {
is = mgr.open(path);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
bitmap = BitmapFactory.decodeStream(is, null, options);
}
catch (final IOException e)
{
bitmap = null;
Log.e(TAG, "FAILED TO get getBitmapFromAsset: " + e.getMessage());
}
finally
{
if (is != null)
{
try
{
is.close();
}
catch (IOException ignored)
{
}
}
}
return bitmap;
}
我已经尝试了几种不同的方法,例如没有 BitmapFactory.Options,但无论我得到 NullPointerException 是什么,所以我猜我应该做另一个过程。
附言我可以从 res/raw 文件夹加载它们,但我没有子目录来组织我的资源。
最佳答案
好的,我刚刚意识到我的 assets 文件夹出于某种原因在 res 文件夹下。我只是把它放在主文件夹 app/main/assets 下,它正在工作。 *脸红
关于java - 从 OpenGL 的 Assets 文件夹加载纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30307515/