I use Android NDK to set color for individual pixel. It looks something like that:
typedef struct {
uint8_t red;
uint8_t green;
uint8_t blue;
uint8_t alpha;
} rgba;
JNIEXPORT void JNICALL Java_com_package_jniBmpTest(JNIEnv* env, jobject obj, jobject bitmapIn, jobject bitmapOut) {
AndroidBitmapInfo infoIn;
void* pixelsIn;
AndroidBitmapInfo infoOut;
void* pixelsOut;
if ((ret = AndroidBitmap_getInfo(env, bitmapIn, &infoIn)) < 0 ||
(ret = AndroidBitmap_getInfo(env, bitmapOut, &infoOut)) < 0) {
return;
}
if (infoIn.format != ANDROID_BITMAP_FORMAT_RGBA_8888 ||
infoOut.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
return;
}
if ((ret = AndroidBitmap_lockPixels(env, bitmapIn, &pixelsIn)) < 0 ||
(ret = AndroidBitmap_lockPixels(env, bitmapOut, &pixelsOut)) < 0) {
LOGE("Error! %d", ret);
}
rgba* input = (rgba*) pixelsIn;
rgba* output = (rgba*) pixelsOut;
int w = infoIn.width;
int h = infoIn.height;
int n;
for (n = 0; y < w * h; n++) {
output[n].red = input[n].red;
output[n].green = input[n].green;
output[n].blue = input[n].blue;
output[n].alpha = 127;
}
AndroidBitmap_unlockPixels(env, bitmapIn);
AndroidBitmap_unlockPixels(env, bitmapOut);
}
I need to set bitmap semi-transparent (it is simplified example - my code is much more complicated, but bug exists in this code, too). Problem is that instead of semi-transparent bitmap as a result I have image with corrupted colors. It is semi-transparent, too, but colors are not correct (for example, white color is black, blue is green...). What's the possible problem?
Thanks for help.