Yalantis/uCrop · error · CImgIOException
load_cimg(): Unsupported pixel type '%s' for file '%s'.
Error message
load_cimg(): Unsupported pixel type '%s' for file '%s'.
What it means
After trying every _cimg_load_cimg_case macro (bool, int8..uint64, float32, float64), load_cimg() throws if no pixel-type string matched the header's declared pixel type (CImg.h:66826). The .cimg header names a pixel type this CImg build does not handle.
Source
Thrown at ucrop/src/main/jni/CImg.h:66826
assign(N);
_cimg_load_cimg_case("bool",0,0,cimg_uint8);
_cimg_load_cimg_case("uint8","unsigned_char","uchar",cimg_uint8);
_cimg_load_cimg_case("int8",0,0,cimg_int8);
_cimg_load_cimg_case("char",0,0,char);
_cimg_load_cimg_case("uint16","unsigned_short","ushort",cimg_uint16);
_cimg_load_cimg_case("int16","short",0,cimg_int16);
_cimg_load_cimg_case("uint32","unsigned_int","uint",cimg_uint32);
_cimg_load_cimg_case("int32","int",0,cimg_int32);
_cimg_load_cimg_case("unsigned_long","ulong",0,cimg_ulong);
_cimg_load_cimg_case("long",0,0,cimg_long);
_cimg_load_cimg_case("uint64","unsigned_int64",0,cimg_uint64);
_cimg_load_cimg_case("int64",0,0,cimg_int64);
_cimg_load_cimg_case("float32","float",0,cimg_float32);
_cimg_load_cimg_case("float64","double",0,cimg_float64);
if (!loaded) {
if (!file) cimg::fclose(nfile);
throw CImgIOException(_cimglist_instance
"load_cimg(): Unsupported pixel type '%s' for file '%s'.",
cimglist_instance,
str_pixeltype._data,filename?filename:"(FILE*)");
}
if (!file) cimg::fclose(nfile);
return *this;
}
//! Load a sublist list from a (non compressed) .cimg file.
/**
\param filename Filename to read data from.
\param n0 Starting index of images to read (~0U for max).
\param n1 Ending index of images to read (~0U for max).
\param x0 Starting X-coordinates of image regions to read.
\param y0 Starting Y-coordinates of image regions to read.
\param z0 Starting Z-coordinates of image regions to read.
\param c0 Starting C-coordinates of image regions to read.
\param x1 Ending X-coordinates of image regions to read (~0U for max).View on GitHub (pinned to f788b534b4)
Solutions
- Fix the pixel type token in the header line to one of: bool, int8/uint8/int16/uint16/int32/uint32/int64/uint64, float32 (float), float64 (double).
- Re-export the data converting to a supported dtype (e.g. float32).
- Check for encoding/CRLF corruption of the pixel-type field and rewrite the header cleanly.
Example fix
// before (header line) 4 float16 little_endian // after 4 float32 little_endian
Defensive patterns
Strategy: validation
Validate before calling
bool supportedPixelType(const char* path) {
std::FILE* f = std::fopen(path, "rb"); if (!f) return false;
char line[256] = {0};
bool got = std::fgets(line, sizeof line, f) != nullptr;
std::fclose(f);
char pt[64] = {0}; char en[64] = {0}; unsigned n;
if (!got || std::sscanf(line, "%u %63s %63s", &n, pt, en) < 2) return false;
static const char* ok[] = {"bool","int8","uint8","int16","uint16","int32","uint32","int64","uint64","float32","float64","float","double"};
for (const char* k : ok) if (!std::strcmp(pt, k)) return true;
return false;
} Try / catch
try {
imgs.load_cimg(path);
} catch (cimg_library::CImgIOException& e) {
if (!supportedPixelType(path)) convertCimgToFloat32(path); // rewrite header + data
else throw;
} Prevention
- Only write .cimg headers with the documented pixel-type tokens
- Convert exotic dtypes (float16/bfloat16) to float32 before export
- Keep the writing and reading CImg versions aligned
- Lint hand-crafted headers against the supported type list
When it happens
Trigger: Loading a .cimg whose header line declares a pixel type other than the supported set (e.g. 'float16', 'bfloat16', or a misspelled type like 'uintt'), or a header line produced by an incompatible/older CImg writer.
Common situations: Data exported by another tool with a custom pixel-type string; typo in a hand-crafted .cimg header; reading files written by a newer CImg with types unavailable in the bundled version.
Related errors
- load_cimg(): File or CImg header not found in file '%s'.
- load_cimg(): CImg header not found in file '%s'.
- cimg::mod(): Specified modulo value is 0.
- assign(): Invalid assignment request of shared instance from
- CImg<%s>::load_inr(): Invalid pixel type '%s' defined in hea
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/9dc92b8bd1b691c7.
Report an issue: GitHub.