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

Passing Integer arguments from Java function to JNI function returning garbage values?

我正在使用 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);

android 和本机方法签名不匹配。

您的 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);