开发者

android ndk native code fopen() path

I am new to programming and tryin开发者_运维问答g to learn android with native c++ code. I am trying to open a bitmap file in native code so I can load it as a texture in opengl.

FILE* img = NULL;
img = fopen("banana.bmp","rb");

if (img == NULL)
{
    __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:LC: [%s]", "load texture file = null");
    return -1;
}

the above code always return img as null.

Where should I put my banana.bmp file?

Right now I put it in the jni folder along with the android.mk and c++ source files.

Can someone please explain to me? Thanks


The NDK fopen() will open resources in the emulator or on the phone, not in your development workspace!

To try this, for example in the emulator, you should push the image to the SD card.


You should specify a folder where to write the "banana.bmp" file. Like in this example:

fp = fopen("/sdcard/banana.bmp", "wb");


I think you need to specify the path to your file. To help you I found this link to explain, but exactly where your .bmp file resides I am not sure. You might have to do a bit of experimenting with file locations.


You're not specifying a path to banana.bmp. Where do you expect it to be found? If it's in a asset of your APK, you can't simply fopen() as such. If you've extracted/downloaded/etc. You'll need a path that is something like /data/data/your.package.name/banana.bmp (note that you'll want to get the actual path from Java/SDK)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜