0

我想在java中创建一个位图,传递它的引用并用c ++对其进行操作,然后在java中查看结果。特别是,我尝试了以下方法,但没有结果:

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();

}

我除了在java端有一个已经改变的位图,但不幸的是它不起作用。

4

1 回答 1

0

您需要进行匹配的调用AndroidBitmap_unlockPixels

此外,以下代码只是用“随机”数据填充您的图片:

pictureRGB = (uint16_t*)malloc(sizeof(uint16_t)*info.width*info.height);
memcpy((char*)pixels, (char*)pictureRGB, info.width*info.height*sizeof(uint16_t));
于 2013-04-17T12:06:02.353 回答