Yalantis/uCrop · error · CImgIOException

load_other(): Failed to open file '%s'.

Error message

load_other(): Failed to open file '%s'.

What it means

CImg's load_other() tries to load an image by auto-detecting its format; if it can't even open the file (fopen fails), it throws CImgIOException. This means the file path is wrong, unreadable, or locked. The library closes any attempted handle and rethrows with the filename embedded.

Source

Thrown at ucrop/src/main/jni/CImg.h:60172

        throw CImgArgumentException(_cimg_instance
                                    "load_other(): Specified filename is (null).",
                                    cimg_instance);

      const unsigned int omode = cimg::exception_mode();
      cimg::exception_mode(0);
      try { load_magick(filename); }
      catch (CImgException&) {
        try { load_imagemagick_external(filename); }
        catch (CImgException&) {
          try { load_graphicsmagick_external(filename); }
          catch (CImgException&) {
            try { load_cimg(filename); }
            catch (CImgException&) {
              try {
                cimg::fclose(cimg::fopen(filename,"rb"));
              } catch (CImgException&) {
                cimg::exception_mode(omode);
                throw CImgIOException(_cimg_instance
                                      "load_other(): Failed to open file '%s'.",
                                      cimg_instance,
                                      filename);
              }
              cimg::exception_mode(omode);
              throw CImgIOException(_cimg_instance
                                    "load_other(): Failed to recognize format of file '%s'.",
                                    cimg_instance,
                                    filename);
            }
          }
        }
      }
      cimg::exception_mode(omode);
      return *this;
    }

    //! Load image using various non-native ways \newinstance.

View on GitHub (pinned to f788b534b4)

Solutions

  1. Verify the file exists at the exact path (std::filesystem::exists or fopen test).
  2. Check read permissions on the file and each parent directory.
  3. On Android, copy assets/ content URIs to a real file path before passing to CImg.
  4. Check the path isn't a directory.
  5. Log the actual filename passed in; check for truncation or encoding issues.

Example fix

// before
CImg<unsigned char> img("/data/data/pkg/cache/photo.png"); // file may not exist
// after
std::ifstream f("/data/data/pkg/cache/photo.png");
if (f.good()) { CImg<unsigned char> img("/data/data/pkg/cache/photo.png"); }
else { /* handle missing file */ }
Defensive patterns

Strategy: try-catch

Validate before calling

bool fileReadable(const char* p){ FILE* f=fopen(p,"rb"); if(!f) return false; fclose(f); return true; }
// call: if (!fileReadable(filename)) handle(); else img.load(filename);

Type guard

bool isReadableFile(const std::string& p){ return std::filesystem::is_regular_file(p) && !std::filesystem::is_empty(p); }

Try / catch

try { img.load(filename); } catch (CImgIOException& e) { fprintf(stderr,"Cannot open image: %s\n", e.what()); }

Prevention

When it happens

Trigger: Calling CImg<T>::load(), load_other(), or an image constructor taking a filename where the file cannot be opened for reading ('rb' fopen fails): nonexistent path, no read permission, or a directory path.

Common situations: Typos in asset paths in Android JNI code (ucrop bundled assets not copied to a real filesystem path), using an Android content:// URI instead of a file path, missing storage permissions.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/bb2eaeb71bf593bf. Report an issue: GitHub.