2012-11-27 7 views
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); 

BitmapTextureAtlasSource 코드 : 작은 화면의 크기를 줄이기 위해 내가 그렇게 할

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) 

말해주십시오 내가 뭘 잘못하고있어. 어떤 정보에 대해서도 감사 할 것입니다.

+0

내가 문제가 BitmapTextureAtlasSource에있을 수 있습니다 생각합니다. 코드를 게시 할 수 있습니까? –

+0

다른 질문은 2048x2048의 BitmapTextureAtlas를 사용하는 것입니다. 심지어 일부 고급 장치는 그 문제에 대해 불평 할 수 있습니다. – jmroyalty

답변

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);  
} 

}

+0

예, 작동합니다! mBitmap.copy (Bitmap.Config.ARGB_8888, true)도 생성자에 삽입하십시오. 많은 분들에게 Rodrigo Dias에게 감사드립니다. – TimaCh

0

해상도 정책을 RatioResolutionPolicy으로 설정하고 엔진에서 사용자를 위해 스케일링을 수행하도록 권장합니다.

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

+0

예, 신청서에 기재했습니다. 하지만 약한 장치에 큰 텍스처를로드하고 싶지는 않습니다. – TimaCh

+0

왜 2 개 (또는 그 이상) 다른 이미지가없고 적절한 이미지를로드해야합니까? – jmroyalty

+0

다양한 기기 (240x320 ~ 720x1280)를 지원하는 경우 APK 크기가 매우 커질 수 있으므로 애니메이션을 사용하는 경우, 다른 해상도에 대해 수백 개의 파일을 생성하는 것은 정말 고통 스럽습니다. –