1

私のアプリケーションでは、高解像度のテクスチャがあります。小さな画面のサイズを小さくするには、次のようにします。

@Override
public void onLoadResources(){
    Options options = new BitmapFactory.Options();
    options.inScaled = false;

    // calculation inSampleSize
    int sm = 1;
    if (cameraWidth+cameraHeight < 1280) sm = 2;// < 800x480
    if (cameraWidth+cameraHeight <  800) sm = 4;// < 480x320
    options.inSampleSize = sm;

    mTexture = new BitmapTextureAtlas(2048/sm, 2048/sm, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    // Loading bitmap
    sky_bm = BitmapFactory.decodeResource(getResources(), R.drawable.sky, options);
    sky_src = new BitmapTextureAtlasSource(sky_bm);

    skyRegion = TextureRegionFactory.createFromSource(mTexture, sky_src, 0, 0, false);

    mEngine.getTextureManager().loadTexture(mTexture);

BitmapTextureAtlasソース コード:

 public class BitmapTextureAtlasSource extends BaseTextureAtlasSource implements IBitmapTextureAtlasSource {

        private Bitmap mBitmap;

        public BitmapTextureAtlasSource(Bitmap pBitmap) {
            super(0,0);
            //this.mBitmap = pBitmap;
            this.mBitmap = pBitmap.copy(Bitmap.Config.ARGB_8888, false);
        }

        public int getWidth() {
            return mBitmap.getWidth();
        }

        public int getHeight() {
            return mBitmap.getHeight();
        }

        @Override
        public BitmapTextureAtlasSource clone() {
            return new BitmapTextureAtlasSource(Bitmap.createBitmap(mBitmap));
        }

        public Bitmap onLoadBitmap(Config pBitmapConfig) {
                return mBitmap;
        }

        @Override
        public IBitmapTextureAtlasSource deepCopy() {
            return null;
        }
    }

しかし、画面を回転させると、次のエラーが表示されます。

FATAL EXCEPTION: GLThread 4895
java.lang.IllegalArgumentException: bitmap is recycled
    at android.opengl.GLUtils.texSubImage2D(GLUtils.java:220)
    at org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas.writeTextureToHardware(BitmapTextureAtlas.java:162)
    at org.anddev.andengine.opengl.texture.Texture.loadToHardware(Texture.java:116)
    at org.anddev.andengine.opengl.texture.TextureManager.updateTextures(TextureManager.java:146)
    at org.anddev.andengine.engine.Engine.onDrawFrame(Engine.java:507)
    at org.anddev.andengine.opengl.view.RenderSurfaceView$Renderer.onDrawFrame(RenderSurfaceView.java:154)
    at net.rbgrn.opengl.GLThread.guardedRun(GLThread.java:235)
    at net.rbgrn.opengl.GLThread.run(GLThread.java:94)

私が間違っていることを教えてください。どんな情報でもありがたいです

4

2 に答える 2

0

解決ポリシーを に設定RatioResolutionPolicyし、エンジンにスケーリングを任せることをお勧めします。

http://andengine.wikidot.com/detect-screen-resolution

于 2012-11-28T01:00:55.370 に答える
0

問題は onLoadBitmap にある可能性があると思います。コピーを返す必要があります。EmptyBitmapTextureAtlasSource を拡張するこの実装を試すことをお勧めします。

public class BitmapTextureSource extends EmptyBitmapTextureAtlasSource {

private Bitmap mBitmap;

public BitmapTextureSource(Bitmap bitmap) {
    super(bitmap.getWidth(), bitmap.getHeight());
    mBitmap = bitmap;       
}

@Override
public Bitmap onLoadBitmap(Config pBitmapConfig) {
    return mBitmap.copy(pBitmapConfig, true);       
}

}

于 2012-11-28T14:10:20.890 に答える