1

下面的代码片段导致错误...... logcat 已附加......我正在尝试将图像路径从 java 代码传递到 NDK 代码,并从那里尝试使用 FreeImage 库打开位图...... .

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);
    }

错误日志

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
4

1 回答 1

2

只有将代码编译为 C++ 代码时,才能调用 JNI 函数。

如果您需要或想要将代码编译为 C,那么您必须按以下方式编写 JNI 调用:

const jsize len      = (*env)->GetStringUTFLength(env, bitmappath);
const char* strChars = (*env)->GetStringUTFChars(env, bitmappath, (jboolean *)0);
于 2012-07-24T05:34:28.943 回答