Available in the LEADTOOLS Imaging toolkit. |
CreateUserBitmap example for C++ 4.0 and later
void CDataDlg::OnButton1()
{
// create an empty variant
COleVariant vEmpty;
// make sure I am using pixels
m_LEAD1.SetScaleMode(3);
// Create the empty user bitmap.
m_LEAD1.CreateUserBitmap(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_LEAD1.SetBitmapDataPointer (vBitmapData, lDataSize);
// save the bitmap
m_LEAD1.Save("c:\\gray.jpg", FILE_JPEG, 0, 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_LEAD1.SetBitmapDataPointer(vEmpty, 0);
}
}
void CDataDlg::OnButton2()
{
m_LEAD1.Load("c:\\gray.jpg", 0, 0, 1);
}