Write Dicom File to memory
Moderator: Moderator Team
Write Dicom File to memory
Hi,
I try to write a dicom file into a memory buffer. I can write a file by using the DcmFileFormat::saveFile method. Now I have written a method DcmFileFormat::saveMem which uses a DcmOutputBufferStream to copy the Dicom file to an address in memory. It works so far but I have some problems to determine the exact size of the buffer to allocate for the dicom file. I tried the method DcmFileFormat::getLength( opt_oxfer, opt_oenctype) with the correct transfer syntax and encoding but the buffer is always about 100-200 bytes to small. How can I get the exact size of the dicom file in the memory?
Thanks in advance!
I try to write a dicom file into a memory buffer. I can write a file by using the DcmFileFormat::saveFile method. Now I have written a method DcmFileFormat::saveMem which uses a DcmOutputBufferStream to copy the Dicom file to an address in memory. It works so far but I have some problems to determine the exact size of the buffer to allocate for the dicom file. I tried the method DcmFileFormat::getLength( opt_oxfer, opt_oenctype) with the correct transfer syntax and encoding but the buffer is always about 100-200 bytes to small. How can I get the exact size of the dicom file in the memory?
Thanks in advance!
-
- DCMTK Developer
- Posts: 120
- Joined: Thu, 2009-11-26, 08:15
It looks like DcmFileFormat::getLength() only calculates the length of the dataset, so the metainfo header is ignored. Does DcmFileFormat::getMetaInfo()->calcElementLength() give you the missing number of bytes? This function should return at least 132 (DCM_PreambleLen + DCM_MagicLen), so this sounds like it's relatively close to your missing number of bytes.
There is also a getLength() method in DcmMetaInfo.
I don't know which of these would return the right value, sorry.
There is also a getLength() method in DcmMetaInfo.
I don't know which of these would return the right value, sorry.
-
- ICSMED DICOM Services
- Posts: 2217
- Joined: Fri, 2004-10-29, 21:38
- Location: Oldenburg, Germany
Hi,
okay I am almost there. If I first call DcmFileFormat::validateMetaInfo( opt_oxfer ) then DcmFileFormat::getLength( opt_oxfer, opt_oenctype ) return almost the exact length of the file. But there are still always 8 Bytes missing. If I add these 8 Bytes to the length all my test files seem to work. Do you have an idea what these 8 Bytes could be?
I want to write the file to shared memory to be able to access it by another process.
okay I am almost there. If I first call DcmFileFormat::validateMetaInfo( opt_oxfer ) then DcmFileFormat::getLength( opt_oxfer, opt_oenctype ) return almost the exact length of the file. But there are still always 8 Bytes missing. If I add these 8 Bytes to the length all my test files seem to work. Do you have an idea what these 8 Bytes could be?
I want to write the file to shared memory to be able to access it by another process.
-
- ICSMED DICOM Services
- Posts: 2217
- Joined: Fri, 2004-10-29, 21:38
- Location: Oldenburg, Germany
This depends on the content of the DICOM file, e.g. there was a fix only yesterday that solved an issue with wrong length calculation.Do you have an idea what these 8 Bytes could be?
However, this issue only occurred when the VR of some data elements changed between reading and writing (e.g. from the invalid VR "??" to "UN").
Btw, what about using the DcmOutputBufferStream with a fixed buffer length, and then flush its content when the buffer is full?
There should be examples in the DCMTK source code on how to use this class that way ...
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest