]> Creatis software - gdcm.git/blob - Example/TestWriteSimple.cxx
379658695c0300789dffb6a0bc666b4c86f05d77
[gdcm.git] / Example / TestWriteSimple.cxx
1 #include "gdcm.h"
2
3 int main(int argc, char* argv[])
4 {
5
6   if (argc < 3) 
7     {
8     std::cerr << "Usage :" << std::endl << argv[0] << 
9       " InputHeader OutputDicom" << std::endl;
10     return 0;
11     }
12
13   std::string header = argv[1];
14   const char *output = argv[2];
15
16   gdcmHeader *f1 = new gdcmHeader( header );
17   gdcmFile   *f2 = new gdcmFile( f1 );
18
19   // If the following call is important, then the API sucks. Why is it
20   // required to allocate PixelData when we are not using it !?
21   void* PixelData = f2->GetImageData(); //EXTREMELY IMPORTANT
22   //Otherwise ReadPixel == -1 -> the dicom writing fails completely
23   
24   int dataSize    = f2->GetImageDataSize();
25   // unsigned char cast is necessary to be able to delete the buffer
26   // since deleting a void* is not allowed in c++
27   uint8_t* imageData = (uint8_t*)f2->GetImageData();
28
29   f2->SetImageData( imageData, dataSize);
30
31   f2->WriteDcmExplVR( output );
32   
33   delete[] imageData;
34   delete f1;
35   delete f2;
36   //delete PixelData; //Does GetImageData return the same pointer ?
37   (void)PixelData;
38
39   return 0;
40 }
41