Search code examples
androidopengl-esbitmaprajawali

Invalid Bitmap format in OpenGl


I use Rajawali library in my app.

I am trying to create png images with option

options.inPurgeable = true;
options.inInputShareable = true;
options.inSampleSize = sampleSize;
options.inDither = false;
options.inScaled = false;
options.inPreferredConfig=Bitmap.Config.RGB_565; 

since i think it reduces memory usage.But it cause a error at

GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, mBitmapFormat, mBitmap, 0);

in the class ASingleTexture;

But if i remove

options.inPreferredConfig=Bitmap.Config.RGB_565;

then no error occur but use high memory.How to solve this issue


Solution

  • If I'm not mistaken, the bitmaps you use for OpenGL textures need to be with ARGB_8888 config. Sure, each bitmap will require more memory this way, but here are a few points to remember:

    1. OpenGL textures are saved in native memory which doesn't have the same limitations as regular memory allocated for apps.
    2. Once you've created your texture, you don't need to hold the bitmap anymore. Call recycle on the bitmap immediately after the texture is loaded, and you should be fine.