I’ve managed to get an android.graphics.Bitmap created and I’m successfully filling it via the SetPixels command.
The problem is that I start off with RGBA data. I then create a jintArray. I then call SetIntArray (effectively memcpying the data into the buffer). Then, finally, I call setPixels to actually set the pixels (which presumably causes another copy).
one big issue with doing this is that whether I used R8G8B8A8 or R5G6B5 or A8 I still have to convert my pixel data to R8G8B8A8 data.
Ideally I’d like a way to fill the buffer using only one copy and allow me to do it without doing the pixel format conversion.
Is there any way to directly get at the buffer data contained in a Bitmap? I see there is a function GetDirectBufferAddress in the JNI, but the documentation I can find on it suggests its limited to a java.nio.buffer. Can I directly get at the pixel data using this function? Perhaps by getting the internal buffer used by the Bitmap class?
Is my only way of using this to create a Global Ref’d Java.nio.buffer then each time I want to update, copy my pixel data into it and then use copyPixelsFromBuffer? This still involves 2 copies but can, at least, eliminate the pixel format change. Is this going to be any more efficient than the method I’m already using?
Is there an even better way of doing it?
Btw, I AM aware of the fact I can use the functions in < android/bitmap.h > but I would really like to not lose support for Android 2.1 and Android 2.2 …
Cheers in advance!
Here comes a dirty yet working solution, working from Android 1.5 up to 4.0.
Code is in C++.