将托管的unsigned char *数组转换为jbyteArray

时间:2014-04-11 02:42:10

标签: c# java c++ java-native-interface

如何将托管的未签名char*转换为jbyte*

因为我是新手,所以一个片段也会有所帮助。

这是我的原生代码: -

JNIEXPORT jobject JNICALL Java_com_me_NativeCaller_processImages
    (JNIEnv *env, jclass c, jbyteArray front, jbyteArray back){
unsigned char* frontBuffer = convertJByteArrayIntoUnsignedChar(env, front);
unsigned char* backBuffer = convertJByteArrayIntoUnsignedChar(env, back);
System::Collections::Generic::List<cli::array<unsigned char>^>^ returnedValue = processImages(frontBuffer,backBuffer);
jbyte* bytes;
bytes = returnedValue[1];
bytes = returnedValue[2];
jbyteArray intermediateArray1 = env->NewByteArray(1);
env->SetByteArrayRegion(intermediateArray1,0,1,bytes);

return static_cast<jobject>(intermediateArray1);
}

bytes = returnedValue[1];我收到错误a value of type cli::array<unsigned char,1>^ cannot be assign to an entity of type jbyte*

c#代码返回byte[]的列表: -

public static List<byte[]> processImages(byte[] frontImage, byte[] backImage)
    {
        CallProcessFrontBackAndMICR(frontImage,backImage);

        List<Image> imagesToReturn = GetAllPages(tiffFileBuffer);//convert byte[] into two separate images
        front = imagesToReturn[0];
        back = imagesToReturn[1];

        List<byte[]> bytesToReturn = new List<byte[]>();
        bytesToReturn.Add(imageToByteArray(front));
        bytesToReturn.Add(imageToByteArray(back));

        return bytesToReturn;
    }
如果有人可以帮助我,那真的很有帮助。

0 个答案:

没有答案