{"record":{"id":"f856b7634cda8891","repo":"Yalantis/uCrop","slug":"save-bmp-instance-is-multispectral-only-the-th","errorCode":null,"errorMessage":"save_bmp(): Instance is multispectral, only the three first channels will be saved in file '%s'.","messagePattern":"save_bmp\\(\\): 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":61501,"sourceCode":"\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;\n      header[0x03] = (file_size>>8)&0xFF;\n      header[0x04] = (file_size>>16)&0xFF;\n      header[0x05] = (file_size>>24)&0xFF;\n      header[0x0A] = 0x36;\n      header[0x0E] = 0x28;","sourceCodeStart":61483,"sourceCodeEnd":61519,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L61483-L61519","documentation":"BMP supports at most 4 channels and CImg's save_bmp() writes RGB(A) at most 3 used channels; images with _spectrum>3 (e.g. CMYK, RGBA+extra, spectral data) trigger this warning and only the first three channels are written. Extra channels are silently dropped.","triggerScenarios":"CImg::save_bmp() or save(\"file.bmp\") on an image with _spectrum > 3, e.g. 4+ channel images produced by feature extraction, CMYK data, or spectral stacks.","commonSituations":"Saving multispectral/feature images to BMP; processing pipelines that keep N channels then export to a viewer format; confusion between RGBA (which is fine at spectrum 4 for other formats but still truncated to RGB here).","solutions":["Save only the channels you need explicitly: img.get_channel(c) per channel, or get_channels(0,2) for RGB.","Use a format that preserves all channels: save_cimg, save_tiff, save_pfm, or save_pnm (for 3/4-channel).","Reduce the image to RGB/grayscale deliberately before export so the output matches intent.","Verify spectrum<=3 when a viewable image is the goal; otherwise pick a data format."],"exampleFix":"// before\nrgba_plus.save_bmp(\"out.bmp\"); // channels 3.. dropped\n// after\nif (rgba_plus.spectrum() > 3) rgba_plus.get_channels(0, 2).save_bmp(\"out.bmp\");\nelse rgba_plus.save_bmp(\"out.bmp\");","handlingStrategy":"validation","validationCode":"if (img.spectrum() > 3) img = img.get_channels(0, 2);\nimg.save_bmp(path);","typeGuard":"bool isRgbWritable(const CImg<T>& im) { return im.spectrum() <= 3; }","tryCatchPattern":null,"preventionTips":["Reduce multispectral data to RGB/grayscale before viewable-format export.","Keep extra channels in data formats (TIFF/CIMG).","Log channel count in export pipelines to catch silent truncation."],"tags":["bmp","saving","multispectral","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"}