CImg icon indicating copy to clipboard operation
CImg copied to clipboard

error when trying to save image inside an existing cimg file

Open tvatooms opened this issue 4 years ago • 3 comments

Hi, When I try to save a Cimg object inside an already existing cimg file , I get errors.


// create empty initial image
 CImg<float>::save_empty_cimg(fileNameCimg.toStdString().c_str(), 1000, 1000);
		
 // trying to insert cimg image inside existing file 
// croppedRaster is sized (500,500)
croppedRaster.save_cimg(fileNameCimg.toStdString().c_str(), 0, 0,0, 0, 0);

[CImg] *** Warning ***cimg::fwrite(): Only 0/501 elements could be written in file

In addition if I save the cimg image as a tiff file, the croppedRaster image is not located at (0,0) but at (500,0)

tvatooms avatar May 17 '21 09:05 tvatooms

This test works for me:

#include "CImg.h"
using namespace cimg_library;

int main() {
  CImg<int>::save_empty_cimg("test.cimg",1000,1000,1,3);
  CImg<int> img(500,500,1,2,0);
  img.rand(0,255);
  img.save_cimg("test.cimg",0,128,128,0,0);

  CImg<int>::get_load_cimg("test.cimg").display("test.cimg");
}

test_cimg

dtschump avatar May 17 '21 12:05 dtschump

Hi David, thanks a lot, I will try this this morning.

tvatooms avatar May 21 '21 08:05 tvatooms

sorry for the late answer, I have tried your code and it works . However, if the subX,Y is (0,0) and not (128,128), I get some issues :

CImg<int>::save_empty_cimg("test.cimg", 1000, 1000, 1, 3);
			CImg<int> img(500, 500, 1, 2, 0);
			img.rand(0, 255);
			img.save_cimg("test.cimg", 0, 0, 0, 0, 0);

			CImg<int>::get_load_cimg("test.cimg").display("test.cimg");

tvatooms avatar Jul 08 '21 15:07 tvatooms