|
这是CDib类里的构造函数
CDib::CDib(char * dibFileName)
{
size=0;
strcpy(m_fileName, dibFileName);
LoadFile(m_fileName);
}
这是CDib类里的加载函数
void CDib::LoadFile(const char* dibFileName)
{ strcpy(m_fileName,dibFileName);
CFile dibFile;
dibFile.Open(m_fileName, CFile::modeRead|CFile::typeBinary);
dibFile.Read((void*)&bitmapFileHeader,sizeof(BITMAPFILEHEADER));//此处为C点,调试到此处就又回到了void CBmp2View::OnDraw(CDC* pDC)不会往下执行
if (bitmapFileHeader.bfType == 0x4d42)
{
DWORD fileLength = dibFile.GetLength();
size = fileLength -sizeof(BITMAPFILEHEADER);
pDib =(BYTE*)GlobalAllocPtr(GMEM_MOVEABLE, size);
dibFile.Read((void*)pDib, size);
dibFile.Close();
m_pBitmapInfo = (BITMAPINFO*) pDib;
m_pBitmapInfoHeader = (BITMAPINFOHEADER*) pDib;
m_pRGB = (RGBQUAD*)(pDib + m_pBitmapInfoHeader->biSize);
int m_numberOfColors = GetNumberOfColors();
if (m_pBitmapInfoHeader->biClrUsed == 0)
m_pBitmapInfoHeader->biClrUsed = m_numberOfColors;
DWORD colorTableSize = m_numberOfColors * sizeof(RGBQUAD);
m_pData = pDib + m_pBitmapInfoHeader->biSize + colorTableSize;
if (m_pRGB == (RGBQUAD*)m_pData) m_pRGB = NULL;
m_pBitmapInfoHeader->biSizeImage = GetSize();
m_valid = true;
}
else
{
m_valid = false;
AfxMessageBox("This isn't a bitmap file!");
}
}
这是在CView类里想用来显示的函数
void CBmp2View::OnDraw(CDC* pDC)//此处为A点
{
CBmp2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CDib cdib("c:\try.bmp");//此处为B点 ,又跳回到A
BYTE *pBitmapData = cdib.GetData();
LPBITMAPINFO pBitmapInfo=cdib.GetInfo();
pDC=GetDC();
::StretchDIBits(pDC->GetSafeHdc(),
0,0,500,500,
0,0,500,500,
pBitmapData,pBitmapInfo,DIB_RGB_COLORS,SRCCOPY);
}
编译可以构建EXE都可以,就是不会显示图像
调试后发现总是在A点和B点间转来转去,其中B点的CDib cdib("c:\try.bmp")函数执行到其内部的C点就不再跳出了回到A点 |
|