Convert double array to jdoubleArray

1,816 views
Skip to first unread message

Tobias

unread,
Nov 26, 2009, 10:16:59 AM11/26/09
to android-ndk
Hello,
I have an array like this one in my C code:

double gl_para[16];

I also have a matrix like this one in my C code:

double patt_trans[3][4];

I need to convert this gl_para to a jdoubleArray and I also need to
somehow convert the matrix as well to something that java understands,
how do I do this?

Best regards,
Tobias Lindberg

Simeon Lee

unread,
Nov 27, 2009, 2:42:26 AM11/27/09
to android-ndk
Hello Tobias

I think the following code might help you.

jbyteArray byteArray;
char msg[50];
int l;

sprintf(msg, "May the force be with you.");
l = strlen(msg);

byteArray = (*env)->NewByteArray(env, l);
(*env)->SetByteArrayRegion( env, byteArray, 0, l, (const jbyte*)msg );



Sorry for it's not exact what you want, but probably there is similar
function for 'double'.
The 'env' variable in above is JNIEnv type, which is cached where I
get it through the native function's parameter.
You can cache the JNIEnv object at JNI_OnLoad or any native functions
you made.

Sincerely,
Simeon Lee

Tobias Lindberg

unread,
Dec 1, 2009, 3:55:49 AM12/1/09
to andro...@googlegroups.com
Hello, thank you very much, your solution helped me, this is how I solved it other people are searching for the same answer:

   double gl_para[16];

    jdoubleArray doubleArray = (*env)->NewDoubleArray(env, 16);
    (*env)->SetDoubleArrayRegion( env, doubleArray, 0, 16, (const jdouble*) gl_para );

    return doubleArray;

2009/11/27 Simeon Lee <db.la...@gmail.com>
--

You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.



Reply all
Reply to author
Forward
0 new messages