]> Creatis software - gdcm.git/blob - Example/TestWriteSimple.cxx
* src/gdcmFile.cxx : now delete the PixelConvert instance.
[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   gdcm::Header *f1 = new gdcm::Header( header );
17   gdcm::File   *f2 = new gdcm::File( 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   uint8_t* 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 f1;
34   delete f2;
35   //delete PixelData; //Does GetImageData return the same pointer ?
36   (void)PixelData;
37
38   return 0;
39 }
40