Load an image dynamically in win32 using VC++
-
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!
-
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 talk about Being HUMAN. I have it in my name AnsHUMAN
-
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 use the GDI+
Graphics.DrawImage
methods[^] to draw most image types.It's completed. Now I'm trying to load image from memory buffer. Are you having any idea?
-
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 toImage.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
GlobalUnlock(hGlobal);IStream* pStream;
// 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);
pStream->Release();RectF destRect; // set values to destination location and size
Graphics graphics(hDC);
graphics.DrawImage(pImage, destRect);
delete pImage; -
It's completed. Now I'm trying to load image from memory buffer. Are you having any idea?
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.
For awesome websites or just to chat check out my blog for more info. . .