I am displaying a live view video from camera. Every frame I download into a byte array (pImageData) which I have to allocate.
Now, to display, I am using a CImage (MFC)
Thanks to Hans for pointing out SHCreateMemStream, which I did not know existed. The code is much cleaner, but still unsure whether SHCreateMemStream creates a copy internally (documentation is unclear)
[edit] As per Jonathan' comments, looks like it still has to make a copy internally. Dang ..
Final code
// pImageData is an array with bytes, size is the sizeOfThatArray
// Still not clear if this is making a copy internally
IStream* pMemStream = SHCreateMemStream(pImageData, size);
CComPtr<IStream> stream;
stream.Attach(pMemStream); // Need to Attach, otherwise ownership is not transferred and we leak memory
CImage image;
image.Load(stream);
// .. display image
image.Destroy();
// No need for further cleanup, CComPtr does the job