|
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!
|
|
|
|
|
|
|
It's completed.
Now I'm trying to load image from memory buffer.
Are you having any idea?
|
|
|
|
|
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:
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
PVOID pvData = GlobalLock(hGlobal);
CopyMemory(pvData, pImageData, dwFileSize); GlobalUnlock(hGlobal);
IStream* pStream;
HRESULT hResult = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
Image* pImage = Image::FromStream(pStream);
pStream->Release();
RectF destRect; Graphics graphics(hDC);
graphics.DrawImage(pImage, destRect);
delete pImage;
|
|
|
|
|
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.
|
|
|
|