1.dicom格式文件下载
- #include "stdafx.h"
- #include "dcmtk\dcmdata\dctk.h"
- #include "DCMTK\dcmimgle\dcmimage.h"
- using namespace std;
- #pragma comment(linker,"/NOD:LIBCMT")
- #pragma comment(lib, "oflog.lib")
- #pragma comment(lib, "ofstd.lib")
- #pragma comment(lib, "dcmimage.lib")
- #pragma comment(lib, "dcmdata.lib")
- #pragma comment(lib, "oflog.lib")
- #pragma comment(lib, "netapi32.lib")
- #pragma comment(lib, "wsock32.lib")
- int _tmain(int argc, _TCHAR* argv[])
- {
- char uid[100];
- DcmFileFormat fileformat;
- DcmMetaInfo *metainfo = fileformat.getMetaInfo();
- DcmDataset *dataset = fileformat.getDataset();
- //***meta group******/
- metainfo->putAndInsertString(DCM_FileMetaInformationVersion, "us test dcm file");
- metainfo->putAndInsertString(DCM_MediaStorageSOPClassUID, UID_RETIRED_UltrasoundImageStorage);
- metainfo->putAndInsertString(DCM_MediaStorageSOPInstanceUID, dcmGenerateUniqueIdentifier(uid,SITE_INSTANCE_UID_ROOT));
- metainfo->putAndInsertString(DCM_TransferSyntaxUID, UID_LittleEndianExplicitTransferSyntax);
- metainfo->putAndInsertString(DCM_ImplementationClassUID,"999.999");
- //***identifying group****/
- dataset->putAndInsertString(DCM_ImageType,"ORIGINAL\\PRIMARY\\TEE\\0011");
- dataset->putAndInsertString(DCM_SOPClassUID, UID_RETIRED_UltrasoundImageStorage);//UID_SecondaryCaptureImageStorage);
- dataset->putAndInsertString(DCM_SOPInstanceUID, dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT));
- dataset->putAndInsertString(DCM_StudyID,"398474");
- dataset->putAndInsertString(DCM_StudyDate,"20100823");
- dataset->putAndInsertString(DCM_StudyTime,"080322");
- dataset->putAndInsertString(DCM_Modality,"US");//OT
- dataset->putAndInsertString(DCM_Manufacturer,"ACME product");
- dataset->putAndInsertString(DCM_ReferringPhysicianName,"ANONY");
- dataset->putAndInsertString(DCM_StudyDescription,"STUDY description");
- dataset->putAndInsertString(DCM_SeriesDescription,"SERIES DESCRIPTION");
- dataset->putAndInsertString(DCM_StageNumber,"1");
- dataset->putAndInsertString(DCM_NumberOfStages,"1");
- dataset->putAndInsertString(DCM_ViewNumber,"1");
- dataset->putAndInsertString(DCM_NumberOfViewsInStage,"1");
- /***patient group*****/
- dataset->putAndInsertString(DCM_PatientID, "PatientID");
- dataset->putAndInsertString(DCM_PatientName, "PatientName");
- dataset->putAndInsertString(DCM_PatientSex, "M");
- dataset->putAndInsertString(DCM_PatientBirthDate,"20000302");
- /************************************************************************/
- /* acquisiton group */
- /************************************************************************/
- //DCM_ProtocolName
- /************************************************************************/
- /* relation group */
- /************************************************************************/
- dataset->putAndInsertString(DCM_StudyInstanceUID,"999.999.2.19941105.112000");
- dataset->putAndInsertString(DCM_SeriesInstanceUID,"999.999.2.19941105.112000.2");
- dataset->putAndInsertString(DCM_SeriesNumber,"2");
- dataset->putAndInsertString(DCM_AccessionNumber,"1");
- //dataset->putAndInsertString(DCM_InstanceNumber,);
- //调窗
- //dataset->putAndInsertString(DCM_WindowCenter, "256");
- //dataset->putAndInsertString(DCM_WindowWidth, "128");
- const int width = 256;
- const int height = 256;
- dataset->putAndInsertString(DCM_InstanceNumber,"1");
- //dataset->putAndInsertString(DCM_PatientOrientation,"HFL");
- dataset->putAndInsertString(DCM_PhotometricInterpretation,"RGB");
- dataset->putAndInsertUint16(DCM_SamplesPerPixel,3);
- dataset->putAndInsertUint16(DCM_BitsAllocated,8);
- dataset->putAndInsertUint16(DCM_BitsStored,8);
- dataset->putAndInsertUint16(DCM_HighBit,7);
- dataset->putAndInsertUint16(DCM_PixelRepresentation,0);
- dataset->putAndInsertUint16(DCM_PlanarConfiguration,0);
- dataset->putAndInsertString(DCM_PixelAspectRatio,"4\\3");
- dataset->putAndInsertUint16(DCM_Rows,width);
- dataset->putAndInsertUint16(DCM_Columns,height);
- BYTE* pData=new BYTE[width*height*3];
- memset(pData, 0, width*height*3);
- for(int y=0; y < height; y++){
- //memset(pData+ y*width*3, y & 0xff0000,width*3);
- for(int x=0; x<width*3; x++)
- {
- if(x%3==0)
- pData[y*width*3+x] = 0xff;
- else
- pData[y*width*3+x] = rand()%256;
- }
- }
- dataset->putAndInsertUint8Array(DCM_PixelData,pData, width*height*3);
- delete[] pData;
- OFCondition status = fileformat.saveFile("d:\\pic\\test.dcm",
- EXS_LittleEndianImplicit,EET_UndefinedLength,EGL_withoutGL);
- if (status.bad())
- {
- printf("\n cannot write dicom file");
- return false;
- }
- return true;
- }