我试图在jni中创建一个长数组,基本上是一些矩形坐标。我试图将其存储在一个已经在java类中创建的长数组中。下面是创建该数组的java代码:
private long[] faceArray = new long[10];
下面是我的jni代码,用于创建和替换 faceArray
:
void CreateJavaLongArray(JNIEnv *env, jlongArray& jLongArray, jobject thiz,
std::multiset<dlib::rectangle> mset) {
jclass cls = env->GetObjectClass(thiz);
jfieldID jLongArrayId = env->GetFieldID(cls, "faceArray", "[J");
jLongArray = (jlongArray) env->GetObjectField(thiz, jLongArrayId);
jlong* body = env->GetLongArrayElements(jLongArray, 0);
env->ReleaseLongArrayElements(jLongArray, body, JNI_ABORT);
jLongArray = env->NewLongArray(mset.size() * 4);
if (mset.empty()) {
ALOGE("No unknown face found...");
return;
}
int i = 0;
ALOGI("Size of the rect set is: %d", mset.size());
const int size = mset.size() * 4;
long long arr[size];
for (auto rect : mset) {
arr[i++] = (long long)rect.left();
arr[i++] = (long long)rect.top();
arr[i++] = (long long)rect.right();
arr[i++] = (long long)rect.bottom();
}
env->SetLongArrayRegion(jLongArray, 0, mset.size() * 4, arr);
}
但是当我运行代码时,我发现java端的数组没有改变。尺寸还是10码。我做错什么了?
暂无答案!
目前还没有任何答案,快来回答吧!