I am trying to use the freeimage library in my project..causes error
-
22-06-2021 - |
Pregunta
The following code snippet causes error....the logcat has been attached...I am tring to pass the image path from teh java code to the NDK code and from there I am trying to open the bitmap using FreeImage library....
JNIEXPORT void JNICALL Java_com_example_ImageActivity_brightness(JNIEnv* env, jobject obj, jstring bitmappath, jfloat brightnessValue)
{
AndroidBitmapInfo info;
int ret;
void* pixels;
if ( !bitmappath ) LString();
const jsize len = env->GetStringUTFLength(bitmappath);
const char* strChars = env->GetStringUTFChars(bitmappath, (jboolean *)0);
std::string Result(strChars, len);
env->ReleaseStringUTFChars(bitmappath, strChars);
FIBITMAP *bitmap = FreeImage_Load(FIF_BMP,Result.c_str(), BMP_DEFAULT);
if (bitmap) {
// bitmap successfully loaded!
FreeImage_Unload(bitmap);
}
Error log
flock@QS57:~/Desktop/android-imagefilter-ndk$ /home/flock/ANDROID/android-ndk-r8/ndk-build
Compile thumb : imageprocessing <= imageprocessing.c
jni/imageprocessing.c: In function 'Java_com_example_ImageActivity_brightness':
jni/imageprocessing.c:77: error: request for member 'GetStringUTFLength' in something not a structure or union
jni/imageprocessing.c:78: error: request for member 'GetStringUTFChars' in something not a structure or union
jni/imageprocessing.c:80: error: expected expression before ':' token
jni/imageprocessing.c:82: error: request for member 'ReleaseStringUTFChars' in something not a structure or union
jni/imageprocessing.c:84: error: 'FIBITMAP' undeclared (first use in this function)
jni/imageprocessing.c:84: error: (Each undeclared identifier is reported only once
jni/imageprocessing.c:84: error: for each function it appears in.)
jni/imageprocessing.c:84: error: 'bitmap' undeclared (first use in this function)
jni/imageprocessing.c:84: error: 'FIF_BMP' undeclared (first use in this function)
jni/imageprocessing.c:84: error: 'Result' undeclared (first use in this function)
jni/imageprocessing.c:84: error: 'BMP_DEFAULT' undeclared (first use in this function)
make: *** [obj/local/armeabi/objs/imageprocessing/imageprocessing.o] Error 1
Solución
The way you are calling JNI functions is possible only if you compile code as C++ code.
If you need or want to compile code as C then you must write JNI calls in following way:
const jsize len = (*env)->GetStringUTFLength(env, bitmappath);
const char* strChars = (*env)->GetStringUTFChars(env, bitmappath, (jboolean *)0);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow