這本書寫的不錯~ 《BEGINNING GAME PROGRAMMING》
但是裏面的程序要是換用了修改了BMP圖像資源,結果是圖像不能正常顯示變黑的了。
DKink|棼紫
2008.4.21
這裏作者忽略了一個小小的問題,...........無壓縮BMP文件的
pBitmapInfo->bmiHeader.biSizeImage 裏面的值不一定是圖像的真實大小,可能是0或者隨意的值。 所以需要重新計算,在Bitmap.cpp裏面,Bitmap類的 兩個Create函數的下面這個位置添加計算biSizeImage的代碼。
// Store the width and height of the bitmap
BITMAPINFO* pBitmapInfo = (BITMAPINFO*)pBitmapImage;
m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth;
m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight;
// 計算biSizeImage填充回去,是增加的代碼
pBitmapInfo->bmiHeader.biSizeImage =
m_iHeight*m_iWidth*((int)pBitmapInfo->bmiHeader.biBitCount)/8;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Get a handle to the bitmap and copy the image bits
PBYTE pBitmapBits;
m_hBitmap = CreateDIBSection(hDC, pBitmapInfo, DIB_RGB_COLORS,
(PVOID*)&pBitmapBits, NULL, 0);
ok,修改好了。我在網上搜到很多人用CreateDIBSection圖像顯示是黑的,應該是同一個問題。