CreateUserBitmap2 example for C++ 5.0 and later
void CCOM_MMDlg::OnButton1()
{
// create an empty variant
COleVariant vEmpty;
ILEADRasterIO *pRasterIO=NULL;
CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, IID_ILEADRasterIO,
(void**)&pRasterIO);
// make sure I am using pixels
m_LEADRasterView1.SetScaleMode(3);
// Create the empty user bitmap.
m_LEADRasterView1.GetRaster().CreateUserBitmap2(640, 480, 24, vEmpty, 0);
long lDataSize = (640 * 480 * 24 / 8);
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = lDataSize;
SAFEARRAY *psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
if(psa)
{
SafeArrayLock(psa);
for(int i = 0; i < lDataSize; i++)
((BYTE *)psa->pvData)[i] = 128; // gray
SafeArrayUnlock(psa);
COleVariant vBitmapData;
V_VT(&vBitmapData) = (VT_ARRAY | VT_UI1);
V_ARRAY(&vBitmapData) = psa;
// set the bitmap data pointer
m_LEADRasterView1.GetRaster().SetBitmapDataPointer2(vBitmapData, lDataSize);
// save the bitmap
pRasterIO->Save(m_LEADRasterView1.GetRaster(), "d:\\temp\\gray.jpg", FILE_JFIF, 0, (QFactorConstants)25, SAVE_OVERWRITE);
// when I go out of scope, the variant will be freed, so
// my bitmap data pointer will be invalid.
// I need to clear the bitmap data pointer
m_LEADRasterView1.GetRaster().SetBitmapDataPointer2(vEmpty, 0);
pRasterIO->Release();
}
}
void CCOM_MMDlg::OnButton2()
{
ILEADRasterIO *pRasterIO=NULL;
CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, IID_ILEADRasterIO, (void**)&pRasterIO);
pRasterIO->Load(m_LEADRasterView1.GetRaster(), "d:\\temp\\gray.jpg", 0, 1, 1);
pRasterIO->Release();
}