CreateUserBitmap example for C++ 5.0 and later
void CCOM_MMDlg::OnButton1()
{
// create an empty variant
COleVariant vEmpty;
ILEADRasterIO *pRasterIO=NULL;
ILEADRasterVariant * pltRasVar = NULL;
ILEADRasterVariant * pltRasVarEmpty = NULL;
CoCreateInstance(CLSID_LEADRasterVariant, NULL, CLSCTX_ALL,
IID_ILEADRasterVariant, (void **)&pltRasVar);
CoCreateInstance(CLSID_LEADRasterVariant, NULL, CLSCTX_ALL,
IID_ILEADRasterVariant, (void **)&pltRasVarEmpty);
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().CreateUserBitmap(640, 480, 24, pltRasVarEmpty, 0);
long lDataSize = (640 * 480 * 24 / 8);
pltRasVar->Type = VALUE_ARRAY_BYTE;
pltRasVar->ItemCount = lDataSize;
for(int i = 0; i < lDataSize; i++)
pltRasVar->ShortItemValue (i) = 128; // gray
// set the bitmap data pointer
m_LEADRasterView1.GetRaster().SetBitmapDataPointer(pltRasVar,
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().SetBitmapDataPointer(pltRasVarEmpty, 0);
pRasterIO->Release();
pltRasVar->Release ();
pltRasVarEmpty->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();
}