Take a look at Image :: Image (IStream *, BOOL) . This takes a pointer to a COM object that implements the IStream interface. You can get one of them by allocating some GlobalAlloc global memory and then calling CreateStreamOnHGlobal in the returned descriptor. It will look something like this:
shared_ptr<Image> CreateImage(BYTE *blob, size_t blobSize) { HGLOBAL hMem = ::GlobalAlloc(GMEM_MOVEABLE,blobSize); BYTE *pImage = (BYTE*)::GlobalLock(hMem); for (size_t iBlob = 0; iBlob < blobSize; ++iBlob) pImage[iBlob] = blob[iBlob]; ::GlobalUnlock(hMem); CComPtr<IStream> spStream; HRESULT hr = ::CreateStreamOnHGlobal(hMem,TRUE,&spStream); shared_ptr<Image> image = new Image(spStream); return image; }
But with error checking and such (omitted here to make things clearer)
source share