J2KCompressionRatio example for C++ 5.0 and later
ILEADDicomDS *pLEADDicomDS = NULL;
BSTR lpLic = SysAllocString(_szLicString);
ILEADDicomFactory *pFactory=NULL;
CoCreateInstance(CLSID_LEADDicomFactory, NULL, CLSCTX_ALL,
IID_ILEADDicomFactory, (void**)&pFactory);
#if _MSC_VER < 1200
pLEADDicomDS = (ILEADDicomDS*)pFactory->CreateObject ("LEADDicomDS.LEADDicomDS", lpLic);
#else
ILEADDicomDSPtr spLEADDicomDS=NULL;
spLEADDicomDS = pFactory->CreateObject ("LEADDicomDS.LEADDicomDS", lpLic);
pLEADDicomDS = spLEADDicomDS;
pLEADDicomDS->AddRef();//because when spLEADDicomDS goes out of scope, it will auto Release()!
#endif
pLEADDicomDS->EnableMethodErrors = FALSE;
// Unlock DICOM & J2K support.
ILEADDicomKernel *pLEADDicomKernel = NULL;
#if _MSC_VER < 1200
pLEADDicomKernel = (ILEADDicomKernel*)pFactory->CreateObject ("LEADDicomKernel.LEADDicomKernel", lpLic);
#else
ILEADDicomKernelPtr spLEADDicomKernel=NULL;
spLEADDicomKernel = pFactory->CreateObject ("LEADDicomKernel.LEADDicomKernel", lpLic);
pLEADDicomKernel = spLEADDicomKernel;
pLEADDicomKernel->AddRef();//because when spLEADDicomKernel goes out of scope, it will auto Release()!
#endif
pFactory->Release();
SysFreeString(lpLic);
pLEADDicomKernel->UnlockSupport (L_SUPPORT_J2K,L_KEY_J2K);
pLEADDicomKernel->UnlockSupport (L_SUPPORT_MEDICAL,L_KEY_MEDICAL);
pLEADDicomKernel->Release();
pLEADDicomDS->InitDS (DICOM_CLASS_CR_IMAGE_STORAGE,
DS_EXPLICIT_VR |
DS_METAHEADER_ABSENT |
DS_LITTLE_ENDIAN);
//load an image
ILEADRasterIO *pRasterIO=NULL;
HRESULT hr;
hr = CoCreateInstance(CLSID_LEADRasterIO,
NULL,
CLSCTX_ALL,
IID_ILEADRasterIO,
(void**)&pRasterIO);
pRasterIO->EnableMethodErrors = FALSE;
pRasterIO->Load(m_LEADRasterView1.GetRaster(), "d:\\lead14\\dist\\images\\dicom\\image3.dic", 0, 1, 1);
AfxMessageBox("Image loaded from File - Wait");
pRasterIO->Release();
//insert the image into the element
pLEADDicomDS->Bitmap = m_LEADRasterView1.GetRaster().GetBitmap();
// Default Options
IDicomJ2KOptionsPtr pJ2K = pLEADDicomDS->J2KOptions();
pJ2K->J2KSetDefaults();
//Use the Compression ratio
pJ2K->J2KCompressionControl = DICOM_J2K_COMP_RATIO;
pJ2K->J2KCompressionRatio= 10;
//set the bitmap
pLEADDicomDS->SetBitmapValue (DICOM_IMAGE_COMPRESSION_J2K_LOSSY,
DICOM_IMAGE_PHOTOMETRIC_MONOCHROME2,
0, 0, 0);
pLEADDicomDS->SaveDS ("d:\\temp\\out.dic", 0);