gpt4 book ai didi

java - 减小纹理的大小

转载 作者:行者123 更新时间:2023-12-01 04:59:19 24 4
gpt4 key购买 nike

对于我的应用程序,我有高分辨率的纹理。为了减小小屏幕的尺寸,我确实喜欢这样做:

@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)

请告诉我我做错了什么。如果有任何信息,我将不胜感激

最佳答案

我认为问题可能出在 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);
}

}

关于java - 减小纹理的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13592706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com