{"record":{"id":"7058e1c0c2e13a94","repo":"Yalantis/uCrop","slug":"save-png-instance-is-multispectral-only-the-th","errorCode":null,"errorMessage":"save_png(): Instance is multispectral, only the three first channels will be saved in file '%s'.","messagePattern":"save_png\\(\\): Instance is multispectral, only the three first channels will be saved in file '(.+?)'\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":62091,"sourceCode":"\n#if defined __GNUC__\n      const char *volatile nfilename = filename; // Use 'volatile' to avoid (wrong) g++ warning\n      std::FILE *volatile nfile = file?file:cimg::fopen(nfilename,\"wb\");\n      volatile double stmin, stmax = (double)max_min(stmin);\n#else\n      const char *nfilename = filename;\n      std::FILE *nfile = file?file:cimg::fopen(nfilename,\"wb\");\n      double stmin, stmax = (double)max_min(stmin);\n#endif\n\n      if (_depth>1)\n        cimg::warn(_cimg_instance\n                   \"save_png(): Instance is volumetric, only the first slice will be saved in file '%s'.\",\n                   cimg_instance,\n                   filename);\n\n      if (_spectrum>4)\n        cimg::warn(_cimg_instance\n                   \"save_png(): Instance is multispectral, only the three first channels will be saved in file '%s'.\",\n                   cimg_instance,\n                   filename);\n\n      if (stmin<0 || (bytes_per_pixel==1 && stmax>=256) || stmax>=65536)\n        cimg::warn(_cimg_instance\n                   \"save_png(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.\",\n                   cimg_instance,\n                   stmin,stmax,filename);\n\n      // Setup PNG structures for write.\n      png_voidp user_error_ptr = 0;\n      png_error_ptr user_error_fn = 0, user_warning_fn = 0;\n      png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,user_error_ptr, user_error_fn,\n                                                    user_warning_fn);\n      if (!png_ptr){\n        if (!file) cimg::fclose(nfile);\n        throw CImgIOException(_cimg_instance","sourceCodeStart":62073,"sourceCodeEnd":62109,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L62073-L62109","documentation":"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.","triggerScenarios":"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.","commonSituations":"Saving 5+ band satellite imagery or scientific channel stacks to PNG, where all bands beyond RGBA silently disappear.","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"],"exampleFix":"// before\nmultispectral.save_png(\"out.png\"); // bands 5+ dropped\n// after\nmultispectral.get_channels(0,3).save_png(\"out.png\");","handlingStrategy":"validation","validationCode":"if (img.spectrum() > 4) img = img.get_channels(0,3); // then save_png","typeGuard":null,"tryCatchPattern":"// warning only; guard by spectrum check before calling save_png","preventionTips":["Check img.spectrum() before saving to PNG","PNG supports at most 4 channels; use TIFF for more"],"tags":["image-encoding","channels","png"],"backgroundTag":"unsupported-operation","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"}