0

I have a problem in my native code because in my c ++ code I can not save the images I receive from the JAVA part.

I tried using cv::imwrite but the image is never saved in the path and in the corresponding folder.

My JNI code is as follows:

extern "C"{
    JNIEXPORT jintArray JNICALL Java_com_example_testNativeCode_DisplayImage_FindFeatures(JNIEnv* env, jclass obj, jintArray bufImg, jint w, jint h){

    jint *cbuf;
    cbuf = env->GetIntArrayElements(bufImg, 0);

    if(cbuf==NULL){
       return 0;
    }

    cv::Mat mImg(h,w,CV_8UC4, (unsigned char*)cbuf);

    cv::imwrite("../SaveImage/img.png", mImg);
    }
}

I use android studio 2.3.3 and OpenCv 3.1.0. I put in the manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

I want to know if it was possible to record an image with cv::imwrite? How else can I do to save it?

Fruchtzwerg
  • 9,895
  • 12
  • 39
  • 45
Tom13000
  • 241
  • 1
  • 13

1 Answers1

0

I am experiencing the same problem,but i solve it by this steps:

1.request permission

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

2.Manually open the permission switch

3.Close app and clear task

4.Open your project app and try again,it it working to me.

If it is not working for you,uninstall and reinstall app,and repeat the above steps