我正在尝试从已安装的obb扩展文件加载纹理,但是AndEngine无法打开该文件。那是我的代码:

    BuildableBitmapTextureAtlas atlas = new BuildableBitmapTextureAtlas(textureManager, 2048, 2048, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath(obbManager.getMainRoot() + "/");
    File file = new File(obbManager.getMainRoot() + "/background.png");
    if (file.exists()) {
        System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    }
    background = BitmapTextureAtlasTextureRegionFactory.createFromAsset(atlas, this, "background.png");


这就是我在Logcat中看到的:

02-10 22:40:09.170: INFO/System.out(20962): !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
02-10 22:40:09.180: ERROR/AndEngine(20962): Failed loading Bitmap in AssetBitmapTextureAtlasSource. AssetPath: /mnt/obb/8d6d9efb8ab5fbfaa452d7ff7e8047c5/background.png
        java.io.FileNotFoundException: /mnt/obb/8d6d9efb8ab5fbfaa452d7ff7e8047c5/background.png
        at android.content.res.AssetManager.openAsset(Native Method)
        at android.content.res.AssetManager.open(AssetManager.java:315)
        at android.content.res.AssetManager.open(AssetManager.java:289)
        at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.create(AssetBitmapTextureAtlasSource.java:48)
        at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.create(AssetBitmapTextureAtlasSource.java:39)
        at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory.createFromAsset(BitmapTextureAtlasTextureRegionFactory.java:140)
        at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory.createFromAsset(BitmapTextureAtlasTextureRegionFactory.java:132)
        at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory.createFromAsset(BitmapTextureAtlasTextureRegionFactory.java:128)


因此,该文件存在,但我仍在获取FileNotFoundException。

最佳答案

我知道了:createFromAsset试图不在我的文件中找到我的文件,而是在apk的/mnt/.../background.png中找到我的文件。所以我应该使用AndEngine的FileBitmapTextureAtlasSource:

BitmapTextureAtlasTextureRegionFactory.createFromSource(atlas, FileBitmapTextureAtlasSource.create(file))

关于android - Andengine:FileNotFoundException:无法在AssetBitmapTextureAtlasSource中加载位图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14803128/

10-13 05:07