{"record":{"id":"f3a389dd5c691e4d","repo":"Yalantis/uCrop","slug":"save-bmp-instance-is-volumetric-only-the-first","errorCode":null,"errorMessage":"save_bmp(): Instance is volumetric, only the first slice will be saved in file '%s'.","messagePattern":"save_bmp\\(\\): 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":61496,"sourceCode":"      \\param filename Filename, as a C-string.\n    **/\n    const CImg<T>& save_bmp(const char *const filename) const {\n      return _save_bmp(0,filename);\n    }\n\n    //! Save image as a BMP file \\overloading.\n    const CImg<T>& save_bmp(std::FILE *const file) const {\n      return _save_bmp(file,0);\n    }\n\n    const CImg<T>& _save_bmp(std::FILE *const file, const char *const filename) const {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_bmp(): 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_bmp(): Instance is volumetric, only the first slice will be saved in file '%s'.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\");\n      if (_spectrum>3)\n        cimg::warn(_cimg_instance\n                   \"save_bmp(): Instance is multispectral, only the three first channels will be saved in file '%s'.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\");\n\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"wb\");\n      CImg<ucharT> header(54,1,1,1,0);\n      unsigned char align_buf[4] = {};\n      const unsigned int\n        align = (4 - (3*_width)%4)%4,\n        buf_size = (3*_width + align)*height(),\n        file_size = 54 + buf_size;\n      header[0] = 'B'; header[1] = 'M';\n      header[0x02] = file_size&0xFF;","sourceCodeStart":61478,"sourceCodeEnd":61514,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L61478-L61514","documentation":"save_bmp() can only write a single 2D bitmap; BMP has no volume representation. When _depth>1 the library warns that only the first slice (z=0) will be written and proceeds, silently discarding the rest of the volume.","triggerScenarios":"CImg::save_bmp() or save(\"file.bmp\") on a volumetric image (_depth>1), e.g. output of volume processing or a 3D crop.","commonSituations":"Saving 3D results with a .bmp extension; generic save() dispatch on filename; exporting the wrong variable (volume instead of one slice) from 3D code.","solutions":["Save a specific slice: volume.get_slice(z).save_bmp(\"slice.bmp\").","Use a multi-slice capable format: save_tiff (pages), save_cimg, or save_analyze for volumes.","Write one BMP per z via a loop if BMP is required for downstream tooling.","Check depth before saving and fail fast if volume data would be dropped."],"exampleFix":"// before\nvolume.save_bmp(\"out.bmp\"); // only slice 0 written\n// after\nfor (int z = 0; z < volume.depth(); ++z)\n  volume.get_slice(z).save_bmp(cimg::format(\"out_z%04d.bmp\", z));","handlingStrategy":"validation","validationCode":"if (img.depth() > 1) throw std::logic_error(\"BMP stores one slice; save slices individually or use TIFF\");\nimg.save_bmp(path);","typeGuard":"bool is2D(const CImg<T>& im) { return im.depth() == 1; }","tryCatchPattern":null,"preventionTips":["Only export viewable 2D images to BMP.","Use save_tiff/save_cimg for volumes.","Explicitly select the slice you intend to export."],"tags":["bmp","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"}