以下代码片段导致错误....已经附加了logcat ...我想将图像路径从teh 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
答案 0 :(得分:2)
只有将代码编译为C ++代码时才可以调用JNI函数。
如果您需要或想要将代码编译为C,则必须按以下方式编写JNI调用:
const jsize len = (*env)->GetStringUTFLength(env, bitmappath);
const char* strChars = (*env)->GetStringUTFChars(env, bitmappath, (jboolean *)0);