android ndk本机代码fopen()路径
我是编程新手,正在尝试使用本机 C++ 代码学习 android。 我正在尝试用本机代码打开一个位图文件,以便我可以将其作为 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;
}
上面的代码总是将 img 返回为 null。
我应该将banana.bmp 文件放在哪里?
现在我将它与 android.mk 和 c++ 源文件一起放在 jni 文件夹中。
有人可以向我解释一下吗?谢谢
I am new to programming and trying 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
NDK fopen() 将在模拟器或手机上打开资源,而不是在您的开发工作区中!
要尝试此操作(例如在模拟器中),您应该将映像推送到 SD 卡。
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.
您应该指定一个文件夹来写入“banana.bmp”文件。
就像这个例子一样:
You should specify a folder where to write the "banana.bmp" file.
Like in this example:
我认为您需要指定文件的路径。为了帮助您,我找到了 此链接 进行解释,但您的 .bmp 文件所在的位置我我不确定。您可能需要对文件位置进行一些试验。
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.
您没有指定banana.bmp 的路径。您希望在哪里找到它?如果它位于 APK 的资产中,则不能简单地使用 fopen() 。如果您已提取/下载/等。您需要一个类似于 /data/data/your.package.name/banana.bmp 的路径(请注意,您需要从 Java/SDK 获取实际路径)
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)