{"record":{"id":"b842a7dbc287908e","repo":"Yalantis/uCrop","slug":"load-failed-to-recognize-format-of-file-s","errorCode":null,"errorMessage":"load(): Failed to recognize format of file '%s'.","messagePattern":"load\\(\\): Failed to recognize format of file '(.+?)'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":56614,"sourceCode":"          else if (!cimg::strcasecmp(f_type,\"jpg\")) load_jpeg(filename);\n          else if (!cimg::strcasecmp(f_type,\"pan\")) load_pandore(filename);\n          else if (!cimg::strcasecmp(f_type,\"png\")) load_png(filename);\n          else if (!cimg::strcasecmp(f_type,\"tif\")) load_tiff(filename);\n          else if (!cimg::strcasecmp(f_type,\"gif\")) load_gif_external(filename);\n          else if (!cimg::strcasecmp(f_type,\"dcm\")) load_medcon_external(filename);\n          else if (!cimg::strcasecmp(f_type,\"webp\")) load_webp(filename);\n          else if (!cimg::strcasecmp(f_type,\"jxl\")) load_jxl(filename);\n          else is_loaded = false;\n        } catch (CImgIOException&) { is_loaded = false; }\n      }\n\n      // If nothing loaded, try to load file with other means.\n      if (!is_loaded) {\n        try {\n          load_other(filename);\n        } catch (CImgIOException&) {\n          cimg::exception_mode(omode);\n          throw CImgIOException(_cimg_instance\n                                \"load(): Failed to recognize format of file '%s'.\",\n                                cimg_instance,\n                                filename);\n        }\n      }\n      cimg::exception_mode(omode);\n      return *this;\n    }\n\n    //! Load image from a file \\newinstance.\n    static CImg<T> get_load(const char *const filename) {\n      return CImg<T>().load(filename);\n    }\n\n    //! Load image from an ascii file.\n    /**\n       \\param filename Filename, as a C -string.\n    **/","sourceCodeStart":56596,"sourceCodeEnd":56632,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L56596-L56632","documentation":"The file opened successfully but every format-specific loader (including load_other, which dispatches by magic number/extension) threw CImgIOException, so load() reports that it cannot recognize the file format. The library opens the file fine but no plugin/loader claims it.","triggerScenarios":"img.load(path) on a file whose magic bytes match no supported format (e.g. WEBP/HEIC in builds without those loaders), a truncated/corrupt image, or a text/JSON file passed to the image loader.","commonSituations":"Android saves HEIC/WEBP by default; uCrop's bundled CImg lacks those loaders. Also hitting this with broken partial downloads or files with wrong extensions.","solutions":["Check the file's magic bytes (first 2-8 bytes) to confirm it is a format CImg supports (BMP/PNG/JPEG/etc.).","Convert/transcode the image to PNG or JPEG with another decoder (BitmapFactory on Android) before loading.","Load pixels manually (decode elsewhere) and construct the CImg from the raw buffer.","Re-enable or register the matching image format library (e.g. ImageMagick/Other plugins via cimg_use_* defines) if the format is supported when configured."],"exampleFix":"// before\nimg.load(path); // HEIC file -> unrecognized\n// after\nif (!hasSupportedMagic(path)) {\n  decodeWithBitmapAndConvertToPng(path, tmpPng);\n  path = tmpPng;\n}\nimg.load(path);","handlingStrategy":"fallback","validationCode":"bool magicSupported(const char* p){ std::ifstream f(p,std::ios::binary); char b[8]={0}; f.read(b,8); return !strncmp(b,\"\\x89PNG\",4)||!strncmp(b,\"\\xFF\\xD8\",2)||!strncmp(b,\"BM\",2)||!strncmp(b,\"GIF\",3); }","typeGuard":null,"tryCatchPattern":"try { img.load(path); } catch (cimg_library::CImgIOException&) { // unknown format: transcode via platform decoder then retry\n  transcodeToPng(path, tmp); img.load(tmp); }","preventionTips":["Check magic bytes before loading rather than trusting extensions","Convert HEIC/WEBP (unsupported by stock CImg) to PNG/JPEG first","Reject zero-byte or truncated files early"],"tags":["cimg","image-loading","file-format","jni"],"backgroundTag":"unsupported-file-format","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"}