JNI unsigned char to byte array
- by Jeff Storey
I'm working with a C++ library that stores image byte data in an array of unsigned characters. My jni function returns a jByteArray (which then gets converted to a BufferedImage on the java side), but I'm not sure how to fill the jByteArray from the unsigned character array (if it is possible). Can anyone provide a snippet for this last part to basically do this:
// size is the size of the unsigned char array
const int size = 100;
unsigned char* buf = new unsigned char[size];
// buf gets passed to another library here to be populated
jbyteArray bArray = env->NewByteArray(size);
// now how do I get the data from buf to bArray?
Thanks,
Jeff