Yalantis/uCrop · error · CImgIOException
load_tiff(): Failed to open file '%s'.
Error message
load_tiff(): Failed to open file '%s'.
What it means
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.
Source
Thrown at ucrop/src/main/jni/CImg.h:58025
cimg_instance,
filename,nb_images,nfirst_frame,nlast_frame,nstep_frame);
if (nfirst_frame>=nb_images) return assign();
if (nlast_frame>=nb_images) nlast_frame = nb_images - 1;
TIFFSetDirectory(tif,0);
CImg<T> frame;
for (unsigned int l = nfirst_frame; l<=nlast_frame; l+=nstep_frame) {
frame._load_tiff(tif,l,bits_per_value,voxel_size,description);
if (l==nfirst_frame)
assign(frame._width,frame._height,1 + (nlast_frame - nfirst_frame)/nstep_frame,frame._spectrum);
if (frame._width>_width || frame._height>_height || frame._spectrum>_spectrum)
resize(std::max(frame._width,_width),
std::max(frame._height,_height),-100,
std::max(frame._spectrum,_spectrum),0);
draw_image(0,0,(l - nfirst_frame)/nstep_frame,frame);
}
TIFFClose(tif);
} else throw CImgIOException(_cimg_instance
"load_tiff(): Failed to open file '%s'.",
cimg_instance,
filename);
return *this;
#endif
}
//! Load image from a TIFF file \newinstance.
static CImg<T> get_load_tiff(const char *const filename,
const unsigned int first_frame=0, const unsigned int last_frame=~0U,
const unsigned int step_frame=1, unsigned int *const bits_per_value=0,
float *const voxel_size=0, CImg<charT> *const description=0) {
return CImg<T>().load_tiff(filename,first_frame,last_frame,step_frame,bits_per_value,voxel_size,description);
}
// (Original contribution by Jerome Boulanger).
#ifdef cimg_use_tiff
template<typename t>View on GitHub (pinned to f788b534b4)
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).
Example fix
// before
img.load_tiff("scan.tif");
// after
std::ifstream f("/data/scan.tif");
if (!f) throw std::runtime_error("scan.tif not found");
img.load_tiff("/data/scan.tif"); Defensive patterns
Strategy: validation
Validate before calling
std::ifstream probe(path, std::ios::binary);
if (!probe) throw std::runtime_error(std::string("cannot open ") + path);
probe.close();
img.load_tiff(path); Try / catch
try { img.load_tiff(path); }
catch (CImgIOException &e) { /* open failed */ showUserError(e.what()); } Prevention
- Use absolute paths on Android
- Check read permissions and storage permissions
- Verify the asset/file is actually packaged and deployed
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.
Related errors
- cimg::fopen(): Specified file path is (null).
- cimg::fopen(): File '%s', specified mode is (null).
- cimg::fopen(): Failed to open file '%s' with mode '%s'.
- cimg::fread(): Invalid reading request of %u %s%s from file
- cimg::fwrite(): Invalid writing request of %u %s%s from buff
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/7402b51a37ea37d9.
Report an issue: GitHub.