我正在處理一個C++庫,它將圖像字節數據存儲在一個無符號字符數組中。我的jni函數返回一個jByteArray(然後轉換爲Java端的BufferedImage),但我不知道如何從無符號字符數組中填充jByteArray(如果可能的話)。任何人都可以進行這最後一部分,基本上做到這一點提供了一個片段:JNI無符號字符到字節數組
// 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?
感謝, 傑夫
我在這裏有點困惑。複製原始的unsigned char數組(不是jarray)在哪裏發生? – 2011-01-06 01:57:07
請參閱編輯後的版本。 – bmargulies 2011-01-06 01:58:51
謝謝。感謝幫助。 – 2011-01-06 02:49:28