是不是程序把bmp都写入exe文件了,,编译了之后就不需要原来的位图了??? 我的exe文件,使用了res文件夹下面的一个位图做启动界面,这个bmp图象有1m大,结果程序编译完了之后就从原来的1.9m变成了3.9m,,,请问如何不把bmp加入exe文件,而是在程序运行的时候调用bmp文件,,使用完了就再释放??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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; } 那你就不要把bmp加到资源中, 用LoadImage! project->add to project->components and controls->vc components->splash screen试试 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, &ps ); } break; 资源被编译进最终的exe文件中了,可以用LoadImage在运行时加载位图文件 不行,,搞了半天还是没弄好。在添加的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(***)搭上关系的呢??对图象处理还是有很多不懂的说。 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; 程序非活动状态如何判断键被按下了 Carray的用法 请问:如何实现截屏(全屏)并保存成Avi格式的文件?????????就这么多的分了,谢谢! 日历控件在debug版和release版的不同表现! SDK下如果按住CTRL键同时响应鼠标单击请问怎么写? [求助] 苦逼学生对MFC外包问题请教 ############ 如何实现数组的动态增加?############# 深入浅出MFC我很不懂,求求大家行个好吧 请问用VS2008C++访问sql2005的流程是什么? 我在必设中遇到这样一个问题 这个问题可真是有够变态~~!!!:: 只知道IP,怎么知道对方的操作系统
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; }
->vc components->splash screen
试试
{
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, &ps ); }
break;
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(***)搭上关系的呢??
对图象处理还是有很多不懂的说。
if(hBitmap == NULL)
{
return false;
}
m_bitmap.Attach(hBitmap);等价与:
if (!m_bitmap.LoadBitmap(IDB_SPLASH))
return FALSE;