GDI+中怎么能把加到资源里的图片加载到Image里亚?
我知道图片在外面可以
Image image(L "Grapes.png ");
加载任何图片到image里.
但我想把图片和工程编译到一起,把图片加到资源里,查看msdn里没发现有把资源加载到image里的函数,怎么办?
[解决办法]
HBITMAP hbitmap;
hbitmap = (HBITMAP)LoadImage(NULL, "图片路径 ",IMAGE_BITMAP,0,0,
LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE);
[解决办法]
先从资源读到IStream中,然后从IStream中加载到GDI+
下面是一个类似的例子
HRESULT CommonDlgBase::get_picture(LPCTSTR restype,UINT resid,IPicture** pic)
{
HRSRC hResLoad = NULL; // handle to loaded resource
HMODULE hExe = NULL; // handle to existing .EXE file
HRSRC hRes = NULL; // handle/ptr. to res. info. in hExe
LPVOID lpResLock = NULL; // pointer to resource data
hRes = FindResource(hExe, MAKEINTRESOURCE(resid), restype);
if (hRes == NULL)
{
return E_FAIL;
}
hResLoad = (HRSRC)LoadResource(hExe, hRes);
if (hResLoad == NULL)
{
return E_FAIL;
}
lpResLock = LockResource(hResLoad);
if (lpResLock == NULL)
{
return E_FAIL;
}
int fileSize = SizeofResource(hExe, hRes);
//Verbose(_T( "SizeofResource return %d "),fileSize);
CComPtr <IStream> pStream = NULL;
CreateStreamOnHGlobal(NULL,TRUE,&pStream);
if(pStream)
{
ULONG uwrite = 0;
pStream-> Write(lpResLock, fileSize,&uwrite);
if(uwrite==fileSize)
{
LARGE_INTEGER li;
li.u.HighPart=0;
li.u.LowPart =0;
pStream-> Seek( li,STREAM_SEEK_SET,0);
HRESULT hr=OleLoadPicture(pStream,0,TRUE,IID_IPicture,(LPVOID*)pic);
return hr;
}
}
else
return E_FAIL;
return 0;
}