The program should take an Image from the SD card and adjust its brightness. And the image is taken from the SD card via the NDK C-code. It is to be noted that the string depicting the path to the image is passed to the NDK via JNI.
Java code:
private void adjustBrightness() {
   imagePath     = (Environment.getExternalStorageDirectory().getPath()+"earthglobe.jpeg").toCharArray();
   brightness(imagePath, brightness);
}
public native void brightness(char[] imagePath, float brightness);
NDK code:
JNIEXPORT void JNICALL Java_com_example_ImageActivity_brightness(JNIEnv * env,char[] bitmappath, jfloat brightnessValue)
{
   string bmpath    =   bitmappath+'\0';
   jobject  obj = fopen( bitmappath , "rb" );
}
                You cannot pass char[] this way.
In Java use:
public static native void brightness(String imagePath, float brightness);
In native use:
std::string ConvertJString(JNIEnv* env, jstring str)
{
   if ( !str ) std::string();
   const jsize len = env->GetStringUTFLength(str);
   const char* strChars = env->GetStringUTFChars(str, (jboolean *)0);
   std::string Result(strChars, len);
   env->ReleaseStringUTFChars(str, strChars);
   return Result;
}
JNIEXPORT void JNICALL Java_com_example_ImageActivity_brightness(JNIEnv * env, jobject obj, jstring bitmappath, jfloat brightnessValue)
{
   std::string bmpath = ConvertJString( env, bitmappath );
   FILE* f = fopen( bmpath.c_str(), "rb" );
   // do something useful here
   fclose( f );
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With