Android: create an 8-bit indexed color bitmap

Hello. I am developing a game application on the Android platform. This is my first Android development experience. In my game will be implemented sprite graphics. I have sprites in 8-bit format with a palette defined for each series of sprites. I need to load these sprites into android.graphics.Bitmap objects. Now I implemented it as follows:

int [] pixels = new int[spriteWidth * spriteHeight]; //here i'm filling pixels array //... pixels[x,y] = myPalette[colorIndex]; Bitmap.createBitmap(spriteWidth, spriteHeight, Bitmap.Config.ARGB_8888); bitmap.setPixels(pixelsArray, 0, spriteWidth, 0, 0, spriteWidth, spriteHeight); 

it works well, but since I specified ARGB_8888, I am forced to use 4 bytes for each pixel, so I am worried about memory usage.

My question is: is there a way to create an 8-bit bitmap with indexed color, define its palette, and define each pixel color index?

PS I noticed that if I manually create a byte stream containing suitable bmp headers, a palette and pixel data, then I can load it correctly using:

 BitmapFactory.decodeStream(bmpStream); 

And here is my second question: if I load images this way, will it be more efficient in terms of memory usage than the solution above? Or maybe bitmapFactory, using its own internal procedure to decode my stream to the same 32 bit per pixel format?

Any help is greatly appreciated. Sorry, my english is not very good.

+4
source share

All Articles