|
This is the constructor in the CDib class
CDib :: CDib (char * dibFileName)
{
size = 0;
strcpy (m_fileName, dibFileName);
LoadFile (m_fileName);
}
This is the loading function in the CDib class
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)); // This is point C. After debugging, it returns to void CBmp2View :: OnDraw (CDC * pDC) will not execute
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!");
}
}
This is the function that I want to display in the CView class
void CBmp2View :: OnDraw (CDC * pDC) // here is point A
{
CBmp2Doc * pDoc = GetDocument ();
ASSERT_VALID (pDoc);
// TODO: add draw code for native data here
CDib cdib ("c:\try.bmp"); // This is point B, and jump back to 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);
}
Compile can build EXE, but the image will not be displayed
After debugging, it is found that it always moves between points A and B. Among them, the CDib cdib ("c:\try.bmp") function at point B does not jump out and return to point A. |
|