我的exe文件,使用了res文件夹下面的一个位图做启动界面,这个bmp图象有1m大,结果程序编译完了之后就从原来的1.9m变成了3.9m,,,请问如何不把bmp加入exe文件,而是在程序运行的时候调用bmp文件,,使用完了就再释放???

解决方案 »

  1.   

    BOOL LoadBitmapFromBMPFile( LPTSTR szFileName, HBITMAP *phBitmap,
       HPALETTE *phPalette )
       {   BITMAP  bm;   *phBitmap = NULL;
       *phPalette = NULL;   // Use LoadImage() to get the image loaded into a DIBSection
       *phBitmap = (HBITMAP)LoadImage( NULL, szFileName, IMAGE_BITMAP, 0, 0,
                   LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
       if( *phBitmap == NULL )
         return FALSE;   // Get the color depth of the DIBSection
       GetObject(*phBitmap, sizeof(BITMAP), &bm );
       // If the DIBSection is 256 color or less, it has a color table
       if( ( bm.bmBitsPixel * bm.bmPlanes ) <= 8 )
       {
       HDC           hMemDC;
       HBITMAP       hOldBitmap;
       RGBQUAD       rgb[256];
       LPLOGPALETTE  pLogPal;
       WORD          i;   // Create a memory DC and select the DIBSection into it
       hMemDC = CreateCompatibleDC( NULL );
       hOldBitmap = (HBITMAP)SelectObject( hMemDC, *phBitmap );
       // Get the DIBSection's color table
       GetDIBColorTable( hMemDC, 0, 256, rgb );
       // Create a palette from the color tabl
       pLogPal = (LOGPALETTE *)malloc( sizeof(LOGPALETTE) + (256*sizeof(PALETTEENTRY)) );
       pLogPal->palVersion = 0x300;
       pLogPal->palNumEntries = 256;
       for(i=0;i<256;i++)
       {
         pLogPal->palPalEntry[i].peRed = rgb[i].rgbRed;
         pLogPal->palPalEntry[i].peGreen = rgb[i].rgbGreen;
         pLogPal->palPalEntry[i].peBlue = rgb[i].rgbBlue;
         pLogPal->palPalEntry[i].peFlags = 0;
       }
       *phPalette = CreatePalette( pLogPal );
       // Clean up
       free( pLogPal );
       SelectObject( hMemDC, hOldBitmap );
       DeleteDC( hMemDC );
       }
       else   // It has no color table, so use a halftone palette
       {
       HDC    hRefDC;   hRefDC = GetDC( NULL );
       *phPalette = CreateHalftonePalette( hRefDC );
       ReleaseDC( NULL, hRefDC );
       }
       return TRUE;   }
      

  2.   

    那你就不要把bmp加到资源中, 用LoadImage!
      

  3.   

    project->add to project->components and controls
    ->vc components->splash screen
    试试
      

  4.   

    The following code demonstrates how to use the LoadBitmapFromBMPFile function:    case WM_PAINT:
       {
         PAINTSTRUCT   ps;
         HBITMAP       hBitmap, hOldBitmap;
         HPALETTE      hPalette, hOldPalette;
         HDC           hDC, hMemDC;
         BITMAP        bm;   hDC = BeginPaint( hWnd, &ps );   if( LoadBitmapFromBMPFile( szFileName, &hBitmap, &hPalette ) )
       {
          GetObject( hBitmap, sizeof(BITMAP), &bm );
          hMemDC = CreateCompatibleDC( hDC );
          hOldBitmap = (HBITMAP)SelectObject( hMemDC, hBitmap );
          hOldPalette = SelectPalette( hDC, hPalette, FALSE );
          RealizePalette( hDC );      BitBlt( hDC, 0, 0, bm.bmWidth, bm.bmHeight,
                  hMemDC, 0, 0, SRCCOPY );      SelectObject( hMemDC, hOldBitmap );
          DeleteObject( hBitmap );
          SelectPalette( hDC, hOldPalette, FALSE );
          DeleteObject( hPalette );
       }
       EndPaint( hWnd, &amp;ps );   }
       break; 
      

  5.   

    资源被编译进最终的exe文件中了,可以用LoadImage在运行时加载位图文件
      

  6.   

    不行,,搞了半天还是没弄好。在添加的splash screen类中,有个create函数:
    BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
    {
    if (!m_bitmap.LoadBitmap(IDB_SPLASH))
    return FALSE;
    BITMAP bm;
    m_bitmap.GetBitmap(&bm);

    return CreateEx(0,
    AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
    NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL);她的onpaint函数是这样的:
    void CSplashWnd::OnPaint()
    {
    CPaintDC dc(this); CDC dcImage;
    if (!dcImage.CreateCompatibleDC(&dc))
    return; BITMAP bm;
    m_bitmap.GetBitmap(&bm); // Paint the image.
    CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap);
    dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
    dcImage.SelectObject(pOldBitmap);
    }
    我应该怎样改呢???loadimage怎么实现与m_bitmap.LoadBitmap(IDB_SPLASH)同样的效果呢???LoadImage的函数原型是:
    HANDLE LoadImage(
      HINSTANCE hinst,   // handle to instance
      LPCTSTR lpszName,  // image to load
      UINT uType,        // image type
      int cxDesired,     // desired width
      int cyDesired,     // desired height
      UINT fuLoad        // load options
    );
    CBitmap m_bitmap是怎么跟HANDLE LoadImage(***)搭上关系的呢??
    对图象处理还是有很多不懂的说。
      

  7.   

    HBITMAP hBitmap = (HBITMAP)::LoadImage(NULL, bmp文件的名字, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
    if(hBitmap == NULL)
    {
    return false;
    }
    m_bitmap.Attach(hBitmap);等价与:
    if (!m_bitmap.LoadBitmap(IDB_SPLASH))
    return FALSE;