OptimizeBuffer Example for Visual C++ 5.0 and later
void CRasterOptimizerSink::OnOptimize (short nPercent)
{
CString strMsg;
strMsg.Format(TEXT("%d"),nPercent);
MessageBox(NULL,strMsg, TEXT("Optimizing"), 0);
}
void COptimizerDlg::OnOptimizeBuffer()
{
int nRet = 0;
ILEADRasterIO * pRasterIO = NULL;
ILEADRasterVariant * pOrgData = NULL;
ILEADRasterVariant * pOptData = NULL;
ILEADOptimizeOptions * pOptions = NULL;
HRESULT hr;
hr = CoCreateInstance(
CLSID_LEADRasterIO,
NULL,
CLSCTX_ALL,
IID_ILEADRasterIO,
(void**)&pRasterIO
);
hr = CoCreateInstance(
CLSID_LEADRasterVariant,
NULL,
CLSCTX_ALL,
IID_ILEADRasterVariant,
(void**)&pOrgData
);
hr = CoCreateInstance(
CLSID_LEADRasterVariant,
NULL,
CLSCTX_ALL,
IID_ILEADRasterVariant,
(void**)&pOptData
);
hr = CoCreateInstance(
CLSID_LEADOptimizeOptions ,
NULL,
CLSCTX_ALL,
IID_ILEADOptimizeOptions,
(void**)&pOptions
);
pRasterIO->Load (m_RasterView1.GetRaster(), TEXT("c:\\slices\\eye.gif"),0,0,1);
pOrgData = pRasterIO->SaveArray(m_RasterView1.GetRaster(), FILE_JPEG, 24, QFACTOR_LEAD_0);
pOptions->Distance = m_pImageOptmizer->DefaultOptions ()->Distance;
pOptions->JPEGColorSpace = m_pImageOptmizer->DefaultOptions ()->JPEGColorSpace ;
pOptions->Percent = m_pImageOptmizer->DefaultOptions ()->Percent ;
pOptions->PickSamePalette = m_pImageOptmizer->DefaultOptions ()->PickSamePalette;
pOptions->PNGQFactor= m_pImageOptmizer->DefaultOptions ()->PNGQFactor ;
pOptions->JPEGQFactor = m_pImageOptmizer->DefaultOptions ()->JPEGQFactor;
nRet = m_pImageOptmizer->OptimizeBuffer (pOrgData, &pOptData, pOptions, TRUE);
if (nRet == 0)
{
pRasterIO->LoadArray (m_RasterView2.GetRaster(), pOptData, 0, 0, -1, pOptData->ItemCount);
}
pRasterIO->Release();
pOrgData->Release();
pOptData->Release();
pOptions->Release();
}