1、 C++ Int型数组 -> java int数组
int ids[size];
for (int i = 0; i < size; ++i){
ids[i] = i+10;
}
jintArray javaArr = env->NewIntArray(size);
env->SetIntArrayRegion(javaArr,0,size,ids);
return javaArr;
2、 C++ String -> java String
std::string fileStr;
if (fileStr.c_str()!= nullptr){
jstring filename = env->NewStringUTF(fileStr.data());
return filename;
}
return null;
3、 C++ Vector -> java 数组
void EditCallback::OnShape(ShapeType shapeType, std::vector<float> vecFeature) {
if (!vecFeature.empty()) {
int size = vecFeature.size();
jfloatArray features = env->NewFloatArray(size);
env->SetFloatArrayRegion(features, 0, size, vecFeature.data());
env->CallVoidMethod(objCallback,
CallBackJniData::editCallBack_onShape_MethodId,
(int) shapeType,features);
}
}
网友评论