At the moment I only seem to be able to save and load these to external
files.
Is there a way that I hold these images in a single block of memory
instead. That way I can store the memory in my own filing system.
Hope someone can help with this
many thanks
Phil
That's what
HRESULT Save(IStream* pStream, REFGUID guidFileType);
is for.
You have to create an object implementing implement IStream interface,
but that would be the easy part.
HTH,
Goran.
Here a sample for loading an image from resource, that might be
helpful:
BOOL LoadFromResource(HINSTANCE hInstance, LPCTSTR szResourceName,
LPCTSTR szResourceType, CImage& img)
{
HRSRC hResource = ::FindResource(hInstance, szResourceName,
szResourceType);
if (!hResource)
return FALSE;
DWORD imageSize = ::SizeofResource(hInstance, hResource);
if (!imageSize)
return FALSE;
const void* pResourceData = ::LockResource(::LoadResource(hInstance,
hResource));
if (!pResourceData)
return FALSE;
HGLOBAL hBuffer = ::GlobalAlloc(GMEM_MOVEABLE, imageSize);
if (hBuffer)
{
HRESULT hr = E_FAIL;
void* pBuffer = ::GlobalLock(hBuffer);
if (pBuffer)
{
::CopyMemory(pBuffer, pResourceData, imageSize);
IStream* pStream = NULL;
if (::CreateStreamOnHGlobal(hBuffer, FALSE, &pStream) == S_OK)
{
hr = img.Load(pStream);
pStream->Release();
}
::GlobalUnlock(hBuffer);
}
::GlobalFree(hBuffer);
hBuffer = NULL;
return (hr == S_OK);
}
return FALSE;
}