我目前正在学习JNI,而且我(这两天)遇到了这个问题。我有一个具有char数组的Object,我想用C和JNI操作它。
我的代码是:
public class ImageWrapper
{
private int[] imagem;
private int width;
private int height;
public ImageWrapper()
{
getImage();
}
private native void getImage();
}
c ++中的如下:
JNIEXPORT void JNICALL Java_jnisample_ImageWrapper_getImage(JNIEnv *env, jobject thisObj)
{
//Get the class object
jclass thisClass = env->GetObjectClass(thisObj);
//Get the width variable and set it to 100
jfieldID idWidth = env->GetFieldID(thisClass, "width", "I");
env->SetIntField(thisObj, idWidth, 100);
//Get the height variable and set it to 100
jfieldID idHeight = env->GetFieldID(thisClass, "height", "I");
env->SetIntField(thisObj, idHeight, image.size().height);
int*data = new int[100*100];
for(int i=0; i< 100*100; i++)
data[i] = i;
//How do I set the imagem array in Java to be filled with the data I created here?
return;
}
我的问题是我如何操纵它以及如何保存任何更改?
谢谢!