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
It appears the problem is because of the premultiplied alpha.
Further testing revealed that the r,g,b values get scaled by the alpha so if I pass a bitmap to jni I need to multiply the r,g,b values by 255 and divide them by the alpha to have the real value that I can do alpha-operations with. When I pass them back I have to do the reverse.
For only copying and operations without alpha that is not necessary, as the alpha will be 255 for maximum opacity and * 255 / 255 negates itself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.