Gdiplus 貼圖(助記) -------------------從資源中載入PNG圖片

 

  從資源中載入圖片,亦可改成從內從中加載:spa

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);
}
相關文章
相關標籤/搜索