C++ and JNI - How to pass an array into a jfloatArray

后端 未结 4 659
谎友^
谎友^ 2020-12-19 10:10

I have been messing with my own little project to teach myself the android ndk using c++ and jni but I can\'t figure out how to pass the data from a java float array to the

4条回答
  •  我在风中等你
    2020-12-19 10:44

    First you can't use jfloatArray directly. Instead, you should do this

    JNIEXPORT jfloatArray JNICALL Java_jnimath_act_JnimathActivity_test
    (JNIEnv *env, jobject obj, jfloatArray fltarray1, jfloatArray fltarray2)
    {
    
    jfloatArray result;
     result = env->NewFloatArray(3);
     if (result == NULL) {
         return NULL; /* out of memory error thrown */
     }
    
    jfloat array1[3];
    jfloat* flt1 = env->GetFloatArrayElements( fltarray1,0);
    jfloat* flt2 = env->GetFloatArrayElements( fltarray2,0);
    
    
    vecLoad(flt1[0], flt1[1], flt1[2], flt2[0], flt2[1], flt2[2]);
    vecAdd(vec, vec2);
    
    array1[0] = vecRtrn[0];
    array1[1] = vecRtrn[1];
    array1[2] = vecRtrn[2];
    
    env->ReleaseFloatArrayElements(fltarray1, flt1, 0);
    env->ReleaseFloatArrayElements(fltarray2, flt2, 0);
    env->SetFloatArrayRegion(result, 0, 3, array1);
    return result;
    
    }
    

    Please use this as a tutorial and study more. As I said before, studying will help you more than practicing at this time.

提交回复
热议问题