当前位置:编程学习 > C/C++ >>

C++加载PNG资源图片

[cpp]
void LoadResImage(int nResID,Image * &lpImage) 

    HMODULE hModule=AfxGetInstanceHandle(); 
    HRSRC hRsrc = ::FindResource (hModule,MAKEINTRESOURCE(nResID),_T("PNG")); // type   
    if (!hRsrc)  
        return;  
    // load resource into memory   
    DWORD len = SizeofResource(hModule, hRsrc);  
    BYTE* lpRsrc = (BYTE*)LoadResource(hModule, 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); 

 

 

摘自 #Define

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,