简体   繁体   中英

pass bitmap reference from java to C++?

I'd like to create a bitmap in java, pass it's reference and manipulate it with c++ and see the result in java. Particularly, I tried the following, but no result:

JNIEXPORT void JNICALL Java_com_dacuda_scannermousetablet_ui_activities_HomeActivity_setChangeBitmap(
    JNIEnv *env, jobject obj, jobject bitmap) {


mainEnv = env;
AndroidBitmapInfo  info;
void*              pixels;
int                ret;

if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {
    return;
}

if (info.format != ANDROID_BITMAP_FORMAT_RGB_565) {
    return;
}

if ((ret =AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {
}

uint16_t *pictureRGB;
int size = sizeof(uint16_t)*info.width*info.height;
pictureRGB = (uint16_t*)malloc(sizeof(uint16_t)*info.width*info.height);
memcpy((char*)pixels, (char*)pictureRGB, info.width*info.height*sizeof(uint16_t));


mEdit = new EditImage((char*)pictureRGB, info.width, info.height);
mEdit->changeBrightness();

}

And I except to have an already changed bitmap in java side but unfortunately it doesn't work.

You need to make a matching call to AndroidBitmap_unlockPixels

Also, the following code just fill your picture with "random" data:

pictureRGB = (uint16_t*)malloc(sizeof(uint16_t)*info.width*info.height);
memcpy((char*)pixels, (char*)pictureRGB, info.width*info.height*sizeof(uint16_t));

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM