Yalantis/uCrop · warning
save_magick(): Instance is multispectral, only the three…
Error message
save_magick(): Instance is multispectral, only the three first channels will be saved in file '%s'.
What it means
Warning from CImg<T>::save_magick() when the image has more than 3 channels (_spectrum>3). The Magick::Image created here is TrueColor RGB (3 channels), so channels beyond the first three (e.g. alpha plus extra bands, multispectral data) are dropped. The save still completes.
Solutions
- Reduce to RGB explicitly before saving (e.g. get_channels(0,2)) or extract the bands you need
- Save extra channels separately as individual images
- Use a format/backend that supports N channels (save_tiff, or .cimg)
- Ignore if dropping alpha/extra bands is acceptable
Example fix
// before
rgba_hyperspectral.save_magick("out.png"); // channels 3+ dropped
// after
rgba_hyperspectral.get_channels(0,2).save_magick("out.png"); Defensive patterns
Strategy: validation
Validate before calling
if (img.spectrum() > 3) img = img.get_channels(0,2); // then save_magick
Try / catch
// warning only; guard by spectrum check before calling save_magick
Prevention
- Check img.spectrum() before saving to RGB-only backends
- Keep extra channels in TIFF/.cimg
When it happens
Trigger: Calling save_magick() on an image whose _spectrum exceeds 3, such as 4-channel RGBA-plus data or N-band hyperspectral images.
Common situations: Saving remote-sensing/hyperspectral imagery, or RGBA images where a 4th channel (alpha) is silently dropped in TrueColorType mode.
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 has pixel values in [%g,%g]…
- save_magick(): Instance is volumetric, only the first slice…
- save_png(): Instance is multispectral, only the three first…
- save_pnm(): Instance is multispectral, only the three first…
- [" cimg_appname "_math_parser] CImg<
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/5a065fe08d564da4.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:61990
\param bytes_per_pixel Force the number of bytes per pixel for the saving, when possible.
**/
const CImg<T>& save_magick(const char *const filename, const unsigned int bytes_per_pixel=0) const {
if (!filename)
throw CImgArgumentException(_cimg_instance
"save_magick(): Specified filename is (null).",
cimg_instance);
if (is_empty()) { cimg::fempty(0,filename); return *this; }
#ifdef cimg_use_magick
double stmin, stmax = (double)max_min(stmin);
if (_depth>1)
cimg::warn(_cimg_instance
"save_magick(): Instance is volumetric, only the first slice will be saved in file '%s'.",
cimg_instance,
filename);
if (_spectrum>3)
cimg::warn(_cimg_instance
"save_magick(): 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_magick(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.",
cimg_instance,
stmin,stmax,filename);
Magick::Image image(Magick::Geometry(_width,_height),"black");
image.type(Magick::TrueColorType);
image.depth(bytes_per_pixel?(8*bytes_per_pixel):(stmax>=256?16:8));
const T
*ptr_r = data(0,0,0,0),
*ptr_g = _spectrum>1?data(0,0,0,1):0,
*ptr_b = _spectrum>2?data(0,0,0,2):0;View on GitHub (pinned to f788b534b4)