我在资源中载入了很多gif图片(二进制),现在需要一幅一幅轮流显示,非常耗内存资源,所以我想显示下一幅之前把前一幅释放,该如何做?另外,请教怎样释放句柄?

解决方案 »

  1.   

    应该很容易,关键是使用后释放,我不清楚你现在是如何做调用Gif的,能说详细点吗?如果用内存设备,则先要Select Out,然后在删除。
      

  2.   

    我是这样写的,
    先调用
    BOOL CVOImage::SetBitmap(HDC hdc, DWORD dwResourceID, LPCTSTR pcszClass, HMODULE hModule)
    {
    if(!g_hdc)
       g_hdc = CreateCompatibleDC(hdc);
    if(m_hbitmap)
       DeleteObject(m_hbitmap); HRESULT hr;
    BYTE    szBuffer[1024] = {0}; 
    DecompressImageInfo dii; CVOResource  res(hModule, dwResourceID, pcszClass); if(!res.IsLoaded())
    {
    return FALSE;
    }
    res.SetUserData(0); // Fill in the 'DecompressImageInfo' structure
    dii.dwSize = sizeof( DecompressImageInfo ); dii.pbBuffer = szBuffer; dii.dwBufferMax = 1024; dii.dwBufferCurrent = 0;
    dii.phBM = &m_hbitmap; dii.ppImageRender = NULL; dii.iBitDepth = GetDeviceCaps(hdc,BITSPIXEL);
    dii.lParam = ( LPARAM ) &res;
    dii.hdc = g_hdc;
    dii.iScale = g_iScale;
    dii.iMaxWidth = g_iMaxWidth;
    dii.iMaxHeight = g_iMaxHeight;
    dii.pfnGetData = GetImageResourceData;
    dii.pfnImageProgress = ImageProgress;
    dii.crTransparentOverride = ( UINT )

             // Process and decompress the image data
    hr = DecompressImageIndirect( &dii );

    BITMAP bmp;
    GetObject(m_hbitmap, sizeof(BITMAP), &bmp);
    m_dwWidth = bmp.bmWidth;
    m_dwHeight = bmp.bmHeight;
    return TRUE;
    }再调用
    HBITMAP CVOImage::Copy()
    {
             BITMAP bm;
             HBITMAP hNew,hOld;
        
             hOld =(HBITMAP) SelectObject(g_hdc, m_hbitmap); ::GetObject(m_hbitmap, sizeof(BITMAP), &bm); HDC hdc = CreateCompatibleDC(g_hdc);
        hNew = CreateCompatibleBitmap(g_hdc,bm.bmWidth,bm.bmHeight);
    SelectObject(hdc, hNew); if(BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, g_hdc, 0, 0, SRCCOPY))
    {
      ::SelectObject(hdc,hOld);
    }
    DeleteDC(hdc);
    return hNew;
    }