How To Get File In Assets From Android NDK -


i'm trying access image file in assets folder native side. can search through assets folder , subdirectories locating particular file looking for:

aassetdir* assetdir = aassetmanager_opendir(asset_manager, "images"); const char* filename; while ((filename = aassetdir_getnextfilename(assetdir)) != null) {    __android_log_print(android_log_debug, "debug", filename); }  aassetdir_close(assetdir); 

i using osg. set image texture shader following code:

texture->setimage(osgdb::readimagefile(filenamewithpath)); 

but file name must include absolute path since not located in same directory. found out cannot absolute path assets directory, being compressed along apk.

being can't access absolute path, other way use image? note, want keep files in asset folder appose sd card.

you can read image asset aassetmanager_open & aasset_read, since asset lies in apk can't filepath name - compressed there. can save data file , read file later or can directly process chunk got asset file if osg allows.

from here:

aassetdir* assetdir = aassetmanager_opendir(mgr, ""); const char* filename = (const char*)null; while ((filename = aassetdir_getnextfilename(assetdir)) != null) {     aasset* asset = aassetmanager_open(mgr, filename, aasset_mode_streaming);     char buf[bufsiz];     int nb_read = 0;     file* out = fopen(filename, "w");     while ((nb_read = aasset_read(asset, buf, bufsiz)) > 0)         fwrite(buf, nb_read, 1, out);     fclose(out);     aasset_close(asset); } aassetdir_close(assetdir); 

Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -