我有一个使用 Visual Studio 6.0 在 MFC 中制作的应用程序,我正在更改位图的颜色深度,该应用程序适用于除 24 位位图图像之外的所有位图。我无法弄清楚为什么它会出错。我知道它给出错误的地方。这是代码。
void CbitmapView::OnMenuRedMode()
{
CBmpViewerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(pDoc->m_bColorModeFlag == TRUE){
#ifdef _DEBUG
CMemoryState oldState,newState,diffState;
oldState.Checkpoint();
#endif
m_bmiView = (BITMAPINFO *)malloc(pDoc->dwInfoSize);
//m_bmiView = (BITMAPINFO *)GlobalAlloc(GPTR,pDoc->dwInfoSize);
CopyMemory(m_bmiView,pDoc->m_bitmapinfo,pDoc->dwInfoSize);
// m_bmiView = pDoc->m_bitmapinfo;
int nColorUsed = m_bmiView->bmiHeader.biClrUsed ;
if(nColorUsed != 0){
for(int i = 0; i < nColorUsed ; i++){
m_bmiView->bmiColors[i].rgbRed = (BYTE)255;
}
}else if(nColorUsed == 0){
nColorUsed = (1 << pDoc->m_bitmapinfo->bmiHeader.biClrUsed);
for(int i = 0; i < nColorUsed ; i++){
m_bmiView->bmiColors[i].rgbRed = (BYTE)255;
}
}
pDoc->m_bmpHandle = CreateDIBSection(NULL, m_bmiView,DIB_RGB_COLORS,
(void **)&pBitsView, NULL, 0);
CopyMemory(pBitsView,pDoc->m_pBits,pDoc->dwBitsSize);
if(m_bmiView != NULL){
//GlobalFree(m_bmiView);
free(m_bmiView); *//error comes at this point when it is 24 bitmap image.*
//delete(m_bmiView);
}
#ifdef _DEBUG
newState.Checkpoint();
if(diffState.Difference(oldState,newState)){
MessageBox(_T("Memory leak detected"));
diffState.DumpAllObjectsSince();
}
#endif
Invalidate();
// TODO: Add your command handler code here
}
}
错误如下VS6.0所示
损坏:在 0x00423DF0 的普通块 (#234) 之后。