Andengine:FileNotFoundException:在AssetBitmapTextureAtlasSource中加载位图失败

时间:2013-02-10 22:04:29

标签: android filesystems andengine

我正在尝试从已安装的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。

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

请尝试使用此

background = BitmapTextureAtlasTextureRegionFactory.createFromAsset(atlas, getAssets(), "background.png");

而不是

background = BitmapTextureAtlasTextureRegionFactory.createFromAsset(atlas, this, "background.png");