Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   Problem_Displaying_bmp_Image (http://www.go4expert.com/forums/problemdisplayingbmpimage-t24172/)

MFC New Bee 14Dec2010 10:08

Problem_Displaying_bmp_Image
 
Hi all,
Presently i am creating a doc/view application in which i read a bmp file's structures like BITMAPFILEHEADER , BITMAPINFOHEADER , COLOR PALETTE and bmBits after that in the view with the help of 'StretchDIBits' i am displaying the bits of the bitmap image . My problem is that only half of the image is displayed can any one help me to solve this problem. Below is the given code.
OnOpenDocument
Code:

BOOL CBmpInfoDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
 FILE *fp;
 fp = _wfopen(lpszPathName , (const wchar_t*) "r");
 if(fp == NULL)
 {
  return FALSE;
 }
 m_pbmiColors = new RGBQUAD[256];
 ZeroMemory(&m_bmfhFileHeader, sizeof(m_bmfhFileHeader));
 /*fread(&m_bmfhFileHeader , sizeof(BITMAPFILEHEADER) ,  1 ,fp);
 
 fread(&m_bmiInfoHead , sizeof(BITMAPINFOHEADER) , 1 , fp);*/
 fread(&m_bmfhFileHeader.bfType , sizeof(m_bmfhFileHeader.bfType) ,
  1 ,fp);
 fread(&m_bmfhFileHeader.bfSize , sizeof(m_bmfhFileHeader.bfSize) ,
  1 , fp);
 fread(&m_bmfhFileHeader.bfReserved1 , sizeof(m_bmfhFileHeader.bfReserved1) ,
    1 , fp);
 fread(&m_bmfhFileHeader.bfReserved2 , sizeof(m_bmfhFileHeader.bfReserved2) ,
    1 , fp);
 fread(&m_bmfhFileHeader.bfOffBits , sizeof(m_bmfhFileHeader.bfOffBits) ,
  1 , fp);
 fread(&m_bmiInfoHead.bmiHeader.biSize , sizeof(m_bmiInfoHead.bmiHeader.biSize) , 1 , fp);
 m_dwSize = m_bmiInfoHead.bmiHeader.biSize;
 fread(&m_bmiInfoHead.bmiHeader.biWidth , sizeof(m_bmiInfoHead.bmiHeader.biWidth) , 1 , fp);
 m_nWidth  = m_bmiInfoHead.bmiHeader.biWidth;
 fread(&m_bmiInfoHead.bmiHeader.biHeight , sizeof(m_bmiInfoHead.bmiHeader.biHeight) , 1 , fp);
 m_nHeight = m_bmiInfoHead.bmiHeader.biHeight;
 fread(&m_bmiInfoHead.bmiHeader.biPlanes , sizeof(m_bmiInfoHead.bmiHeader.biPlanes) , 1 , fp);
 m_wPlanes = m_bmiInfoHead.bmiHeader.biPlanes;
 fread(&m_bmiInfoHead.bmiHeader.biBitCount , sizeof(m_bmiInfoHead.bmiHeader.biBitCount) , 1 , fp);
 m_nBpp = m_bmiInfoHead.bmiHeader.biBitCount;
 fread(&m_bmiInfoHead.bmiHeader.biCompression , sizeof(m_bmiInfoHead.bmiHeader.biCompression) , 1 , fp);
 m_dwCompression =  m_bmiInfoHead.bmiHeader.biCompression;
 fread(&m_bmiInfoHead.bmiHeader.biSizeImage , sizeof(m_bmiInfoHead.bmiHeader.biSizeImage) , 1 , fp);
 fread(&m_bmiInfoHead.bmiHeader.biXPelsPerMeter , sizeof(m_bmiInfoHead.bmiHeader.biXPelsPerMeter) , 1 , fp);
 m_lHorzResolution = m_bmiInfoHead.bmiHeader.biXPelsPerMeter;
 fread(&m_bmiInfoHead.bmiHeader.biYPelsPerMeter , sizeof(m_bmiInfoHead.bmiHeader.biYPelsPerMeter) , 1 , fp);
 m_lVertResolution = m_bmiInfoHead.bmiHeader.biYPelsPerMeter;
 fread(&m_bmiInfoHead.bmiHeader.biYPelsPerMeter , sizeof(m_bmiInfoHead.bmiHeader.biYPelsPerMeter) , 1 , fp);
 fread(&m_bmiInfoHead.bmiHeader.biClrUsed , sizeof(m_bmiInfoHead.bmiHeader.biClrUsed) , 1 , fp);
 fread(&m_bmiInfoHead.bmiHeader.biClrImportant , sizeof(m_bmiInfoHead.bmiHeader.biClrImportant) , 1 , fp);
 int nNoOfPalette = pow(double(2) , double(m_bmiInfoHead.bmiHeader.biBitCount));
 if(m_bmiInfoHead.bmiHeader.biBitCount <= 8)
 {
  for(int nId = 0 ; nId < nNoOfPalette ; nId++)
  {
  fread(&m_pbmiColors[nId].rgbBlue    , sizeof(m_pbmiColors) , 1 , fp);
  fread(&m_pbmiColors[nId].rgbGreen      , sizeof(m_pbmiColors) , 1 , fp);
  fread(&m_pbmiColors[nId].rgbRed    , sizeof(m_pbmiColors) , 1 , fp);
  fread(&m_pbmiColors[nId].rgbReserved  , sizeof(m_pbmiColors) , 1 , fp);
  }
 }
 int nSize = WIDTHBYTES((m_bmiInfoHead.bmiHeader.biWidth)* ((DWORD)m_bmiInfoHead.bmiHeader.biBitCount)) *
      m_bmiInfoHead.bmiHeader.biHeight;
 m_bmBits = new BYTE[nSize];
 fread(m_bmBits , sizeof(m_bmBits) , nSize , fp);
 m_bFlag = TRUE;
 return TRUE;
}

Draw Method
Code:

void CBmpInfoView::OnDraw(CDC* pDC)
{
 CDC* memDC;
 BITMAPINFO m_bmiInfoHead;
 BITMAPINFO *m_pbmiInfo;
 BITMAPFILEHEADER* m_BitmapFileHeader;
 pDoc = GetDocument();
 if(pDoc->GetFlagState() == FALSE)
 {
  return;
 }
 SelectClipRgn(pDC->GetSafeHdc(), NULL);
 m_bmiInfoHead = pDoc->GetBitInfoHead();
 m_BitmapFileHeader = &pDoc->GetBitMapFileHeader();
 m_pbmiInfo = (BITMAPINFO*)(m_BitmapFileHeader + 1);
 BYTE *bits = (BYTE*)m_BitmapFileHeader + m_BitmapFileHeader->bfOffBits;
 bits = (BYTE*)pDoc->GetbmBits();
 m_pbmiInfo = &m_bmiInfoHead;
 StretchDIBits(pDC->GetSafeHdc() , 0 , 0 , m_bmiInfoHead.bmiHeader.biWidth , m_bmiInfoHead.bmiHeader.biHeight ,
      0 , 0 , m_bmiInfoHead.bmiHeader.biWidth , m_bmiInfoHead.bmiHeader.biHeight , bits ,
      m_pbmiInfo , DIB_PAL_COLORS, SRCCOPY);
}



All times are GMT +5.5. The time now is 14:38.