How can I modify an Android bitmap in C++ (JNI/NDK) so that I can use on the Java side?

Posted by HardCoder on Stack Overflow See other posts from Stack Overflow or by HardCoder
Published on 2012-06-09T22:34:52Z Indexed on 2012/06/09 22:40 UTC
Read the original article Hit count: 190

Filed under:
|
|
|
|

I call a C++ function over JNI and pass a RGBA_8888 bitmap, lock it, change the values, unlock it, return and then display it in Java with this C++ code:

AndroidBitmap_getInfo(env, map, &info) < 0);
AndroidBitmap_lockPixels(env, map, (void**)&pixel);

for(i=info.width*info.height-1;i>=0;i--)
{   pixel[i] = 0xf1f1f1f1;
}

AndroidBitmap_unlockPixels(env, map);

The problem I have is that the bitmaps looks not as I expect it and the pixel values (verified with getPixel) are not the same when I check them in Java from what I set them in C++. When I set the bitmap values to 0xffffffff I get the correct value in Java, but for many others I don't. 0xf1f1f1f1 for example turns into 0xF1FFFFFF.

What do I have to do to make it work ?

PS: I am using Android 2.3.4

© Stack Overflow or respective owner

Related posts about java

Related posts about android