I'm creating an application in which I'll have to load an image using open file dialog. there may be any image from system and will have to display that. I'll not have to save my image in resource because its not defined which image is going to be displayed. Application is win32 API not MFC. How can I do it? Thanks!
You can copy the buffer to a global memory buffer, then use CreateStreamOnHGlobal[^] to get the image buffer as a stream, which can then be passed to Image.FromStream[^]. The following should (I hope) help to clarify it:
// allocate a global memory block and copy the image data to it// dwFileSize is size of image buffer in memory (or file size if reading directly)
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
PVOID pvData = GlobalLock(hGlobal);
CopyMemory(pvData, pImageData, dwFileSize); // pImageData is source memory buffer
// create IStream* from global memory which will// be freed automatically when the stream is released
HRESULT hResult = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
Image* pImage = Image::FromStream(pStream);
RectF destRect; // set values to destination location and size
Hi Toms, you could use the CxImage library - which allows you to specify the image bits when constructing an image, or you could use CreateDIBSection to create a bitmap using the image data you already have, then display it using an HDC.