JNI:如何将对象作为参数从java传递给JNI

时间:2014-08-01 07:45:59

标签: java c++ object android-ndk java-native-interface

我是Java的初学者,也是JNI的初学者。 =(

我想将我的对象传递给JNI函数,我的对象是这样的:

class FEATUREINFO
{
    string str_ID;
    char[] c_ID;
    public Double[] featureData;
    int group;
    IplImage *t_faceImg;
    public FEATUREINFO()
    {
        this.featureData = new Double[1280] ;
    }    
} // class FEATUREINFO

然后我创建了100个FEATUREINFO:

FEATUREINFO[] p_featureNode = initializeWithDefaultFEATUREINFOInstances(100);

我要调用的JNI函数是:

JNIEXPORT jint JNICALL Java_com_example_opencvtest_MainActivity_JNIDoFaceGrouping(JNIEnv *env, jobject obj, FEATUREINFO * p_featureNode, jint t_size_fea, jdoubleArray d_Matrix )
{
    // transform double[] to double*, it is to match type of C++ function
    double* Matrix=(double*)env->GetDoubleArrayElements(d_Matrix,0);
    env->ReleaseDoubleArrayElements(d_Matrix,Matrix,0);

    // I don't know how to access the value of p_featureNode.
    // If I want to get the value of p_featureNode[3].featureData[8], how to do?

    DoFaceGrouping(p_featureNode,t_size_fea,Matrix);  // reall C function I use. 
    // the definition of DoFaceGrouping:
    // int DoFaceGrouping(FEATUREINFO * p_facefeature,int t_size_fea,double* d_Matrix)
} 

我不知道如何获取和设置p_featureNode的字段(或属性?)。

请帮帮我。非常感谢你!

增加: 在Java ~~ 我定义了我的Java本机代码:

public static native int DoFaceGrouping(FEATUREINFO[] p_featureNode, int size_fea, double[] Matrix) ; 

我称之为:

int nRet =0; 
nRet = DoFaceGrouping(p_featureNode,t_size_fea,d_Matrix); 

0 个答案:

没有答案