简体   繁体   English

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

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

I am calling a JNI function with int values as parameters. 我正在用int值作为参数调用JNI函数。 I am sending width and height as 800 and 480. But when I try to print these values in the JNI function I am getting 1 and 0 instead of 800 and 480. Why I am getting wrong values in JNI? 我发送的宽度和高度分别为800和480。但是当我尝试在JNI函数中打印这些值时,得到的是1和0,而不是800和480。为什么在JNI中得到的值是错误的?

My JNI function call is: 我的JNI函数调用是:

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

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

And the JNI function is: 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);

The android and native method signatures don't match. android和本机方法签名不匹配。

Your Java native method should look like this: 您的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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM