1. 定义一个DcmFileFormat
DcmFileFormat m_fileformat;
2. 更新传输协议字段
m_fileformat.getDataset()->updateOriginalXfer();
3. 填充tag信息
FillInfo(DCM_SpecificCharacterSet, m_charset);
FillInfo(DCM_MediaStorageSOPInstanceUID, m_image->SOPInstanceUID);
FillInfo(DCM_PhotometricInterpretation, m_image->PhotometricInterpretation);
FillInfo(DCM_Rows, std::to_string(m_image->Rows));
FillInfo(DCM_Columns, std::to_string(m_image->Columns));
FillInfo(DCM_BitsAllocated, std::to_string(m_image->BitsAllocated));
FillInfo(DCM_BitsStored, std::to_string(m_image->BitsStored));
FillInfo(DCM_HighBit, std::to_string(m_image->HighBit));
FillInfo(DCM_PixelRepresentation, std::to_string(m_image->PixelRepresentation));
FillInfo(DCM_RescaleIntercept, std::to_string(m_image->RescaleIntercept));
FillInfo(DCM_RescaleSlope, std::to_string(m_image->RescaleSlope));
FillInfo(DCM_WindowCenter, std::to_string(m_image->WindowCenter));
FillInfo(DCM_WindowWidth, std::to_string(m_image->WindowWidth));
FillInfo(DCM_PixelSpacing, QString("%1\\%2").arg(m_image->PixelSpaing.x()).arg(m_image->PixelSpaing.y()));
m_fileformat.getDataset()->putAndInsertUint16Array(DCM_PixelData, m_image->PixelData, dataLength / pixelByteCount);
4. 执行数据保存
网上很多资料都是基于一个dicom模板,然后进行保存的。本文是基于一个空的dcmFileFormat,进行转换。所以使用了不同的FileWriteMode。参考如下:
/*
typedef enum {
/// write as fileformat (update only missing information, this is the old behavior)
EWM_fileformat = 0,
/// write as dataset (without meta header)
EWM_dataset = 1,
/// write as fileformat and update required information (e.g. SOP Class/Instance UID)
EWM_updateMeta = 2,
/// write as fileformat and create new meta header (do not retain existing information)
EWM_createNewMeta = 3,
/// write as fileformat but don't update the meta header (please be careful!)
EWM_dontUpdateMeta = 4
} E_FileWriteMode;
*/
我们将采用EWM_dataset进行dicom文件保存:
OFCondition status = m_fileformat.saveFile(filePath.c_str(), EXS_LittleEndianExplicit,
EET_UndefinedLength, EGL_recalcGL, EPD_noChange, 0, 0, EWM_dataset);