{"record":{"id":"ff2616177884e34b","repo":"Yalantis/uCrop","slug":"save-jpeg-instance-is-volumetric-only-the-firs","errorCode":null,"errorMessage":"save_jpeg(): Instance is volumetric, only the first slice will be saved in file '%s'.","messagePattern":"save_jpeg\\(\\): 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":61660,"sourceCode":"      \\param quality Image quality (in %)\n    **/\n    const CImg<T>& save_jpeg(const char *const filename, const unsigned int quality=100) const {\n      return _save_jpeg(0,filename,quality);\n    }\n\n    //! Save image as a JPEG file \\overloading.\n    const CImg<T>& save_jpeg(std::FILE *const file, const unsigned int quality=100) const {\n      return _save_jpeg(file,0,quality);\n    }\n\n    const CImg<T>& _save_jpeg(std::FILE *const file, const char *const filename, const unsigned int quality) const {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_jpeg(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(file,filename); return *this; }\n      if (_depth>1)\n        cimg::warn(_cimg_instance\n                   \"save_jpeg(): Instance is volumetric, only the first slice will be saved in file '%s'.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\");\n\n#ifndef cimg_use_jpeg\n      if (!file) return save_other(filename,quality);\n      else throw CImgIOException(_cimg_instance\n                                 \"save_jpeg(): Unable to save data in '(*FILE)' unless libjpeg is enabled.\",\n                                 cimg_instance);\n#else\n      unsigned int dimbuf = 0;\n      J_COLOR_SPACE colortype = JCS_RGB;\n\n      switch (_spectrum) {\n      case 1 : dimbuf = 1; colortype = JCS_GRAYSCALE; break;\n      case 2 : dimbuf = 3; colortype = JCS_RGB; break;\n      case 3 : dimbuf = 3; colortype = JCS_RGB; break;\n      default : dimbuf = 4; colortype = JCS_CMYK; break;","sourceCodeStart":61642,"sourceCodeEnd":61678,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L61642-L61678","documentation":"JPEG stores a single 2D image; save_jpeg() cannot write volumes. When _depth>1 the library warns that only the first slice (z=0) is saved and proceeds, so the remaining slices are silently lost (unless the no-libjpeg fallback path redirects to save_other, which has the same limitation).","triggerScenarios":"CImg::save_jpeg() or save(\"file.jpg\") on a volumetric image (_depth>1), e.g. medical volumes, 3D simulation stacks, or image sequences kept in one CImg instance.","commonSituations":"Exporting 3D stacks to JPEG for previews; save() dispatching on .jpg/.jpeg extension for volume data; z-stack processing pipelines exporting the wrong variable.","solutions":["Save a chosen slice: volume.get_slice(z).save_jpeg(\"slice.jpg\").","Use save_tiff (multi-page) or save_cimg to keep the whole volume in one file.","Loop over z and write one JPEG per slice with a numbered filename scheme.","If quality matters, prefer lossless formats (PNG/TIFF) instead of JPEG for volume slices."],"exampleFix":"// before\nvolume.save_jpeg(\"out.jpg\"); // only slice 0 saved\n// after\nfor (int z = 0; z < volume.depth(); ++z)\n  volume.get_slice(z).save_jpeg(cimg::format(\"out_z%04d.jpg\", z), 95);","handlingStrategy":"validation","validationCode":"if (img.depth() > 1) throw std::logic_error(\"JPEG stores one slice; save slices individually or use TIFF\");\nimg.save_jpeg(path, quality);","typeGuard":"bool is2D(const CImg<T>& im) { return im.depth() == 1; }","tryCatchPattern":null,"preventionTips":["Select the target slice explicitly before JPEG export.","Use multi-page TIFF or CIMG for volume storage.","Prefer lossless formats when fidelity matters."],"tags":["jpeg","saving","volume","data-loss"],"backgroundTag":"unsupported-operation","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}