Yalantis/uCrop · warning
load_ascii(): Only %lu/%lu values read from file
Error message
load_ascii(): Only %lu/%lu values read from file '%s'.
What it means
CImg::load_ascii() parses whitespace-separated numeric values from a .cimg/.ascii file using fscanf("%lf..."); when fscanf stops returning 1 before the expected number of values is read, CImg warns with the count actually read (off-1 of siz) and returns the partially filled image. The image is truncated, not the correct size/content.
Solutions
- Verify the file contains exactly width*height*depth*spectrum numeric values matching its header
- Check the file size/completeness (re-transfer or re-export the file if truncated)
- Open the file and inspect the area around value off-1 for non-numeric garbage
- Check the fscanf return value path: treat the partially filled image as invalid instead of using it
- Regenerate the file programmatically (e.g. save in binary .cimg format) to avoid ASCII parsing issues
Example fix
// before
CImg<float> img;
img.load_ascii("data.txt"); // truncated file -> partial data
// after
std::FILE* f = std::fopen("data.txt", "r");
CImg<unsigned long> dims;
dims.load_cimg_header(f); // or validate value count beforehand
cimg::fclose(f);
CImg<float> img;
img.load_ascii("data.txt"); Defensive patterns
Strategy: validation
Validate before calling
bool asciiDataComplete(const char* path, unsigned long expected) {
std::ifstream in(path);
double v; unsigned long n = 0;
while (in >> v) ++n;
return n == expected;
} Prevention
- Prefer binary .cimg over ASCII for large data
- Validate the value count against the header before load_ascii
- Never hand-edit ASCII data files; regenerate programmatically
- Verify file integrity (size/checksum) after transfers
When it happens
Trigger: Loading an ASCII CImg file whose text contains fewer parseable numbers than the header-declared size, or non-numeric garbage where a value was expected; also a mid-file I/O error.
Common situations: Hand-edited data files with missing values; files truncated by a failed transfer or interrupted save; locale/text issues introducing unexpected characters; wrong file passed to load_ascii.
Related errors
- cimg::fclose(): Error code
- cimg::fclose(): Specified file is (null).
- cimg::fempty(): Specified filename is (null).
- cimg::fopen(): Failed to open file
- cimg::fopen(): File ' ', specified mode is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/c3d1029c9e6d9b8a.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:56682
if (!dx || !dy || !dz || !dc) {
if (!file) cimg::fclose(nfile);
throw CImgIOException(_cimg_instance
"load_ascii(): Invalid ascii header in file '%s', image dimensions are set "
"to (%u,%u,%u,%u).",
cimg_instance,
filename?filename:"(FILE*)",dx,dy,dz,dc);
}
assign(dx,dy,dz,dc);
const ulongT siz = size();
ulongT off = 0;
double val;
T *ptr = _data;
for (err = 1, off = 0; off<siz && err==1; ++off) {
err = std::fscanf(nfile,"%lf%*[^0-9.eEinfa+-]",&val);
*(ptr++) = (T)val;
}
if (err!=1)
cimg::warn(_cimg_instance
"load_ascii(): Only %lu/%lu values read from file '%s'.",
cimg_instance,
off - 1,siz,filename?filename:"(FILE*)");
if (!file) cimg::fclose(nfile);
return *this;
}
//! Load image from a DLM file.
/**
\param filename Filename, as a C-string.
**/
CImg<T>& load_dlm(const char *const filename) {
return _load_dlm(0,filename);
}
//! Load image from a DLM file \newinstance.
static CImg<T> get_load_dlm(const char *const filename) {View on GitHub (pinned to f788b534b4)