Yalantis/uCrop · warning
save_png(): Instance is multispectral, only the three first
Error message
save_png(): Instance is multispectral, only the three first channels will be saved in file '%s'.
What it means
Warning from CImg<T>::save_png() when the image has more than 4 channels (_spectrum>4). PNG supports at most 4 channels (RGBA), so channels beyond the first four are dropped from the output. The save continues normally.
Source
Thrown at ucrop/src/main/jni/CImg.h:62091
#if defined __GNUC__
const char *volatile nfilename = filename; // Use 'volatile' to avoid (wrong) g++ warning
std::FILE *volatile nfile = file?file:cimg::fopen(nfilename,"wb");
volatile double stmin, stmax = (double)max_min(stmin);
#else
const char *nfilename = filename;
std::FILE *nfile = file?file:cimg::fopen(nfilename,"wb");
double stmin, stmax = (double)max_min(stmin);
#endif
if (_depth>1)
cimg::warn(_cimg_instance
"save_png(): Instance is volumetric, only the first slice will be saved in file '%s'.",
cimg_instance,
filename);
if (_spectrum>4)
cimg::warn(_cimg_instance
"save_png(): Instance is multispectral, only the three first channels will be saved in file '%s'.",
cimg_instance,
filename);
if (stmin<0 || (bytes_per_pixel==1 && stmax>=256) || stmax>=65536)
cimg::warn(_cimg_instance
"save_png(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.",
cimg_instance,
stmin,stmax,filename);
// Setup PNG structures for write.
png_voidp user_error_ptr = 0;
png_error_ptr user_error_fn = 0, user_warning_fn = 0;
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,user_error_ptr, user_error_fn,
user_warning_fn);
if (!png_ptr){
if (!file) cimg::fclose(nfile);
throw CImgIOException(_cimg_instanceView on GitHub (pinned to f788b534b4)
Solutions
- Select the channels to keep before saving: img.get_channels(0,3)
- Save extra channels as separate PNG images
- Use a format supporting arbitrary channel counts (save_tiff, .cimg, PFM)
- Ignore if the first four channels are all you need
Example fix
// before
multispectral.save_png("out.png"); // bands 5+ dropped
// after
multispectral.get_channels(0,3).save_png("out.png"); Defensive patterns
Strategy: validation
Validate before calling
if (img.spectrum() > 4) img = img.get_channels(0,3); // then save_png
Try / catch
// warning only; guard by spectrum check before calling save_png
Prevention
- Check img.spectrum() before saving to PNG
- PNG supports at most 4 channels; use TIFF for more
When it happens
Trigger: Calling save_png() on an image with _spectrum>4, e.g. multispectral/hyperspectral imagery with many bands, or a tensor whose channel dimension was repurposed.
Common situations: Saving 5+ band satellite imagery or scientific channel stacks to PNG, where all bands beyond RGBA silently disappear.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- save_magick(): Instance is multispectral, only the three fir
- save_png(): Instance is volumetric, only the first slice wil
- save_png(): Instance has pixel values in [%g,%g], probable t
- save_pnm(): Instance is multispectral, only the three first
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Type of first a
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/7058e1c0c2e13a94.
Report an issue: GitHub.