Yalantis/uCrop · error · CImgIOException

load_medcon_external(): Failed to load file '%s' with extern

Error message

load_medcon_external(): Failed to load file '%s' with external command 'medcon'.

What it means

load_medcon_external() runs the external 'medcon' tool to convert a DICOM file to an Analyze (.hdr/.img) pair in a temp location, then looks for the generated header file (<body>.hdr or m000-<body>.hdr). If neither exists after medcon ran, it throws this CImgIOException: the external conversion produced no usable output.

Source

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

        throw CImgArgumentException(_cimg_instance
                                    "load_medcon_external(): Specified filename is (null) or does not exist.",
                                    cimg_instance);
      CImg<charT> command(1024), filename_tmp(256), body(256);
      do {
        cimg_snprintf(filename_tmp,filename_tmp._width,"%s.hdr",cimg::filenamerand());
      } while (cimg::path_exists(filename_tmp));
      cimg_snprintf(command,command._width,"\"%s\" -w -c anlz -o \"%s\" -f \"%s\"",
                    cimg::medcon_path(),
                    CImg<charT>::string(filename_tmp)._system_strescape().data(),
                    CImg<charT>::string(filename)._system_strescape().data());
      cimg::system(command,cimg::medcon_path());
      cimg::split_filename(filename_tmp,body);

      cimg_snprintf(command,command._width,"%s.hdr",body._data);
      if (!cimg::path_exists(command)) {
        cimg_snprintf(command,command._width,"m000-%s.hdr",body._data);
        if (!cimg::path_exists(command)) {
          throw CImgIOException(_cimg_instance
                                "load_medcon_external(): Failed to load file '%s' with external command 'medcon'.",
                                cimg_instance,
                                filename);
        }
      }
      load_analyze(command);
      std::remove(command);
      cimg::split_filename(command,body);
      cimg_snprintf(command,command._width,"%s.img",body._data);
      std::remove(command);
      return *this;
    }

    //! Load image from a DICOM file, using Medcon's external tool 'medcon' \newinstance.
    static CImg<T> get_load_medcon_external(const char *const filename) {
      return CImg<T>().load_medcon_external(filename);
    }

View on GitHub (pinned to f788b534b4)

Solutions

  1. Verify 'medcon' is installed and on PATH ('medcon -V'); install xmedcon if missing.
  2. Run 'medcon -f <file> -c int -o /tmp' manually to see medcon's actual error on this DICOM.
  3. Check the DICOM file is valid and readable ('dcmdump <file>' or similar) and not truncated.
  4. Ensure the temp directory is writable so medcon can produce its .hdr/.img output.
  5. Use a DICOM library (e.g. dcmtk) or pre-converted Analyze/NIfTI file instead of the external path.

Example fix

// before
img.load_medcon_external("scan.dcm");
// after
if (cimg::system("medcon -V","medcon")!=0)
  throw std::runtime_error("medcon not installed");
img.load_medcon_external("scan.dcm");
Defensive patterns

Strategy: try-catch

Validate before calling

if (!path || !cimg::is_file(path)) throw std::invalid_argument("DICOM missing");
if (cimg::system("medcon -V","medcon")!=0) throw std::runtime_error("medcon not installed");

Type guard

bool medconReady(const char* p){ return p && cimg::is_file(p) && cimg::system("medcon -V","medcon")==0; }

Try / catch

try { img.load_medcon_external(path); }
catch (CImgIOException& e) { log("medcon conversion produced no output; check DICOM validity"); throw; }

Prevention

When it happens

Trigger: Calling load_medcon_external(filename) where the 'medcon' command ran (or failed silently) but did not create the expected .hdr file — medcon not installed so the command did nothing, unsupported DICOM transfer syntax, or medcon naming its output differently than expected.

Common situations: medcon (xmedcon) not installed in the runtime environment; non-standard or corrupted DICOM files that medcon cannot convert; medcon version behaving differently about output filenames; read-protected input DICOM.

Related errors


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