{"record":{"id":"0102a3ffc21f166b","repo":"Yalantis/uCrop","slug":"save-png-instance-is-volumetric-only-the-first","errorCode":null,"errorMessage":"save_png(): Instance is volumetric, only the first slice will be saved in file '%s'.","messagePattern":"save_png\\(\\): Instance is volumetric, only the first slice will be saved in file '(.+?)'\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":62085,"sourceCode":"      cimg::unused(bytes_per_pixel);\n      if (!file) return save_other(filename);\n      else throw CImgIOException(_cimg_instance\n                                 \"save_png(): Unable to save data in '(*FILE)' unless libpng is enabled.\",\n                                 cimg_instance);\n#else\n\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;","sourceCodeStart":62067,"sourceCodeEnd":62103,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L62067-L62103","documentation":"Warning from CImg<T>::save_png() when the image is volumetric (_depth>1). libpng writes a single 2D image, so only the first slice (z=0) is saved and the remaining slices are dropped. The save completes without an error.","triggerScenarios":"Calling save_png() on an image with depth > 1, e.g. a volume loaded from a 3D format or constructed with a depth dimension greater than 1.","commonSituations":"Exporting z-stacks, CT/MRI volumes, or frame sequences (stored as depth) to PNG.","solutions":["Save slices individually: cimg_for_z(img,z) img.get_slice(z).save_png(...);","Use save_tiff or the native .cimg format for volumes","Append frames to an animated PNG/APNG path if supported by the build","Ignore the warning if only the first slice is needed"],"exampleFix":"// before\nvolume.save_png(\"out.png\");\n// after\ncimg_for_z(volume,z) volume.get_slice(z).save_png(cimg::format(\"out_%d.png\",z));","handlingStrategy":"validation","validationCode":"if (img.depth() > 1) { /* save slices or choose another format */ }","typeGuard":null,"tryCatchPattern":"// warning only; guard by depth check before calling save_png","preventionTips":["Check img.depth() before saving to PNG","Use TIFF/.cimg for volumes"],"tags":["image-encoding","volumetric-data","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"}