Copying jbytearray into unsigned char array.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Rasik_Fulzele
Posted On:   Wednesday, August 29, 2001 08:44 PM

I'm accessing jbytearray from Java to C++ program and want to copy the jbyteArray in C++ into array of type 'unsigned char' and of same length . Following code I wrote: JNIEXPORT void JNICALL Java_UserFrontEnd_ImageSensor_FPMMatch (JNIEnv *env, jobject, jbyteArray minut){ unsigned char minut1[400]; //array in cpp jsize len = env->GetArrayLength(minut); //this gives len = 400 jbyte *minbyteA = env->GetByteArrayElements(minut, 0); //Now how do I copy minut into minut1 ? env->ReleaseByteArrayElements(minut, minbyteA, 0); }    More>>

I'm accessing jbytearray from Java to C++ program and want to copy the jbyteArray in C++ into array of type 'unsigned char' and of same length .

Following code I wrote:

			
JNIEXPORT void JNICALL Java_UserFrontEnd_ImageSensor_FPMMatch
(JNIEnv *env, jobject, jbyteArray minut){

unsigned char minut1[400]; //array in cpp

jsize len = env->GetArrayLength(minut); //this gives len = 400

jbyte *minbyteA = env->GetByteArrayElements(minut, 0);

//Now how do I copy minut into minut1 ?

env->ReleaseByteArrayElements(minut, minbyteA, 0);

}
   <<Less

Re: Copying jbytearray into unsigned char array.

Posted By:   Alexander_Krapf  
Posted On:   Thursday, August 30, 2001 07:20 PM

Hi Rasik,



Well, you have a jbyte * and an unsigned char *, so you can simply say


memcpy( minut1, minbyteA, len );

If you're worried about the size of native chars, then you can put in an assertion that blows up when you build on a platform with a different char size, for example:


assert( 1 == sizeof(unsigned char) );

Am I missing a part of the problem?


Good luck,


Alex

About | Sitemap | Contact