{"record":{"id":"7402b51a37ea37d9","repo":"Yalantis/uCrop","slug":"load-tiff-failed-to-open-file-s","errorCode":null,"errorMessage":"load_tiff(): Failed to open file '%s'.","messagePattern":"load_tiff\\(\\): Failed to open file '(.+?)'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":58025,"sourceCode":"                     cimg_instance,\n                     filename,nb_images,nfirst_frame,nlast_frame,nstep_frame);\n\n        if (nfirst_frame>=nb_images) return assign();\n        if (nlast_frame>=nb_images) nlast_frame = nb_images - 1;\n        TIFFSetDirectory(tif,0);\n        CImg<T> frame;\n        for (unsigned int l = nfirst_frame; l<=nlast_frame; l+=nstep_frame) {\n          frame._load_tiff(tif,l,bits_per_value,voxel_size,description);\n          if (l==nfirst_frame)\n            assign(frame._width,frame._height,1 + (nlast_frame - nfirst_frame)/nstep_frame,frame._spectrum);\n          if (frame._width>_width || frame._height>_height || frame._spectrum>_spectrum)\n            resize(std::max(frame._width,_width),\n                   std::max(frame._height,_height),-100,\n                   std::max(frame._spectrum,_spectrum),0);\n          draw_image(0,0,(l - nfirst_frame)/nstep_frame,frame);\n        }\n        TIFFClose(tif);\n      } else throw CImgIOException(_cimg_instance\n                                   \"load_tiff(): Failed to open file '%s'.\",\n                                   cimg_instance,\n                                   filename);\n      return *this;\n#endif\n    }\n\n    //! Load image from a TIFF file \\newinstance.\n    static CImg<T> get_load_tiff(const char *const filename,\n                                 const unsigned int first_frame=0, const unsigned int last_frame=~0U,\n                                 const unsigned int step_frame=1, unsigned int *const bits_per_value=0,\n                                 float *const voxel_size=0, CImg<charT> *const description=0) {\n      return CImg<T>().load_tiff(filename,first_frame,last_frame,step_frame,bits_per_value,voxel_size,description);\n    }\n\n    // (Original contribution by Jerome Boulanger).\n#ifdef cimg_use_tiff\n    template<typename t>","sourceCodeStart":58007,"sourceCodeEnd":58043,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L58007-L58043","documentation":"load_tiff() calls TIFFOpen() on the given filename; when that returns null (file missing, unreadable, or not openable by libtiff), the library throws a CImgIOException reporting failure to open the file.","triggerScenarios":"img.load_tiff(\"/path/missing.tif\") where the file does not exist, the process lacks read permission, or the path is wrong relative to the working directory.","commonSituations":"Typo'd or relative paths in a mobile/JNI app where the working directory differs from expectations, files not packaged with the app, or storage permissions missing.","solutions":["Verify the file exists at the exact path passed (check with a stat/ifstream before loading).","Use an absolute path, especially in Android where the cwd is not the app directory.","Check file read permissions and, on Android, ensure storage permissions are granted.","Confirm the file is a readable TIFF (libtiff fails to open malformed headers too)."],"exampleFix":"// before\nimg.load_tiff(\"scan.tif\");\n// after\nstd::ifstream f(\"/data/scan.tif\");\nif (!f) throw std::runtime_error(\"scan.tif not found\");\nimg.load_tiff(\"/data/scan.tif\");","handlingStrategy":"validation","validationCode":"std::ifstream probe(path, std::ios::binary);\nif (!probe) throw std::runtime_error(std::string(\"cannot open \") + path);\nprobe.close();\nimg.load_tiff(path);","typeGuard":null,"tryCatchPattern":"try { img.load_tiff(path); }\ncatch (CImgIOException &e) { /* open failed */ showUserError(e.what()); }","preventionTips":["Use absolute paths on Android","Check read permissions and storage permissions","Verify the asset/file is actually packaged and deployed"],"tags":["cimg","tiff","file-io"],"backgroundTag":"file-open-failed","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}