Gdiplus 贴图(助记) -------------------从资源中载入PNG图片

 

  从资源中载入图片,亦可改为从内从中加载:

void LoadResImage(int nResID,Image * &lpImage)
{
    HINSTANCE hIns=AfxGetInstanceHandle();
    HRSRC hRsrc = ::FindResource (hIns,MAKEINTRESOURCE(nResID),_T("PNG")); // type 
    if (!hRsrc) 
        return; 
    // load resource into memory 
    DWORD len = SizeofResource(hIns, hRsrc); 
    BYTE* lpRsrc = (BYTE*)LoadResource(hIns, hRsrc); 
    if (!lpRsrc) 
        return; 
    // Allocate global memory on which to create stream 
    HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len); 
    BYTE* pmem = (BYTE*)GlobalLock(m_hMem); 
    memcpy(pmem,lpRsrc,len); 
    IStream* pstm; 
    CreateStreamOnHGlobal(m_hMem,FALSE,&pstm); 
    // load from stream 
    lpImage=Gdiplus::Image::FromStream(pstm);
    // free/release stuff 
    GlobalUnlock(m_hMem); 
    pstm->Release(); 
    FreeResource(lpRsrc);
}

 

转载于:https://www.cnblogs.com/a-live/p/3222567.html

你可能感兴趣的:(Gdiplus 贴图(助记) -------------------从资源中载入PNG图片)