将Java函数中的Integer参数传递给返回垃圾值的JNI函数?

时间:2015-03-31 09:49:16

标签: java android c java-native-interface

我正在使用int值作为参数调用JNI函数。我发送宽度和高度为800和480.但是当我尝试在JNI函数中打印这些值时,我得到1和0而不是800和480.为什么我在JNI中得到错误的值?

我的JNI函数调用是:

findSquare(sourceImage.getNativeObjAddr(),
                        imageTaken.getNativeObjAddr(), 1, width, height);

public native void findSquare(long matAddrRgba, long matAddrDescriptor,
        int draw, int width, int height);

JNI功能是:

JNIEXPORT jint JNICALL 
Java_info_androidhive_androidcameraapi_CameraMainActivity_findSquare(
        JNIEnv*, jobject, jlong addrRgba, jlong addrDescriptor, jlong addrSrc,
        jlong addrDst, jint draw, jint width, jint height);

1 个答案:

答案 0 :(得分:4)

android和native方法签名不匹配。

您的Java本机方法应如下所示:

// added addrSrc, addrDst which were missing.
public native void findSquare(long matAddrRgba, long matAddrDescriptor, 
                              long addrSrc, long addrDst, int draw, int width, 
                              int height);