changing bitmap to transparent by jni but get black

1

I want to change a bitmap loaded with format Bitmap.Config.ARGB_8888 to transparent by jni.

#define MAKE_RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))

...

AndroidBitmapInfo info;
memset(&info, 0, sizeof(info));
AndroidBitmap_getInfo(env, bitmap, &info)
int res = AndroidBitmap_lockPixels(env, bitmap, &pixels);
int tr = 0, tg = 0, tb = 0, ta = 0;
int width = info.width;
for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
        void *pixel = ((uint32_t *)pixels) + y * width + x;

        *((uint32_t *)pixel) = MAKE_RGBA(tr, tg, tb, ta);
    }
}
AndroidBitmap_unlockPixels(env, bitmap);

I read one pixel from app by this:

int value = paintBitmap.getPixel(0, 0);
int r = (value & 0x00ff0000)>>16;
int g = (value & 0x0000ff00)>>8;
int b = value & 0x000000ff;
int a = (value & 0xff000000)>>24;

But I get value -16777216 and alpha -1 and the transformed bitmap is totally black.

How can I solve this problem? Thank you!

android
bitmap
android-ndk
asked on Stack Overflow Mar 19, 2018 by huyn • edited Mar 19, 2018 by huyn

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0