Yalantis/uCrop · error · CImgIOException
save_medcon_external(): Failed to save file '%s' with extern
Error message
save_medcon_external(): Failed to save file '%s' with external command 'medcon'.
What it means
save_medcon_external() first saves the image in ANALYZE format to a temp file, then runs the external 'medcon' tool to convert it to DICOM. This error is thrown when the 'medcon' system command returns a non-zero exit status, meaning the DICOM conversion failed and the target file was not produced.
Source
Thrown at ucrop/src/main/jni/CImg.h:63843
**/
const CImg<T>& save_medcon_external(const char *const filename) const {
if (!filename)
throw CImgArgumentException(_cimg_instance
"save_medcon_external(): Specified filename is (null).",
cimg_instance);
if (is_empty()) { cimg::fempty(0,filename); return *this; }
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));
save_analyze(filename_tmp);
cimg_snprintf(command,command._width,"\"%s\" -w -c dicom -o \"%s\" -f \"%s\"",
cimg::medcon_path(),
CImg<charT>::string(filename)._system_strescape().data(),
CImg<charT>::string(filename_tmp)._system_strescape().data());
if (cimg::system(command,cimg::medcon_path())!=0)
throw CImgIOException(_cimg_instance
"save_medcon_external(): Failed to save file '%s' with external command 'medcon'.",
cimg_instance,
filename);
std::remove(filename_tmp);
cimg::split_filename(filename_tmp,body);
cimg_snprintf(filename_tmp,filename_tmp._width,"%s.img",body._data);
std::remove(filename_tmp);
if (!cimg::path_exists(filename)) {
cimg_snprintf(command,command._width,"m000-%s",filename);
if (!cimg::path_exists(command)) {
cimg::fclose(cimg::fopen(filename,"r"));
throw CImgIOException(_cimg_instance
"save_medcon_external(): Failed to save file '%s' with external command 'medcon'.",
cimg_instance,
filename);
}
}View on GitHub (pinned to f788b534b4)
Solutions
- Verify medcon is installed and cimg::medcon_path() points to it; run the constructed 'medcon -w -c dicom ...' command manually to see the real error.
- Install or upgrade (X)Medcon to a version supporting the image geometry/pixel type.
- Check that the temp and output directories are writable.
- Convert the image to a supported type/geometry before calling save_medcon_external().
- Use an alternative DICOM writing library (e.g. dcmtk) if medcon is unavailable.
Example fix
// before
img.save_medcon_external("slice.dcm");
// after
try { img.save_medcon_external("slice.dcm"); }
catch (CImgIOException& e) { std::fprintf(stderr, "medcon failed: %s", e.what()); img.save_analyze("slice.img"); } Defensive patterns
Strategy: try-catch
Validate before calling
bool medconAvailable() { return std::system("medcon -v > /dev/null 2>&1") == 0; }
// also ensure image geometry/type are DICOM-compatible before saving Try / catch
try {
img.save_medcon_external(dicomFile);
} catch (CImgIOException& e) {
std::fprintf(stderr, "medcon conversion failed: %s", e.what());
// fall back to ANALYZE output or another DICOM writer
} Prevention
- Install (X)Medcon on all hosts running the pipeline and check medcon_path().
- Match image dimensions/pixel type to what medcon's DICOM encoder accepts.
- Keep temp and output directories writable.
- Test with the medcon version deployed; output behavior varies between versions.
When it happens
Trigger: Calling save_medcon_external(filename) when: medcon is not installed or cimg::medcon_path() is wrong; the medcon DICOM conversion fails on the generated ANALYZE temp data (unsupported dimensions/pixel type); permissions or disk issues abort the conversion.
Common situations: Medical imaging pipelines deployed on hosts without (X)Medcon installed; medcon version too old for the image geometry; 3D/volumetric or unusual pixel-type images that medcon's dicom converter rejects.
Related errors
- load_medcon_external(): Failed to load file '%s' with extern
- save_graphicsmagick_external(): Failed to save file '%s' wit
- save_imagemagick_external(): Failed to save file '%s' with e
- save_medcon_external(): Specified filename is (null).
- save_other(): Failed to save file '%s'. Format is not native
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/08eb7dac13e9c811.
Report an issue: GitHub.