1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Display_Bitmap_Image

Discussion in 'MFC' started by MFC New Bee, Dec 9, 2010.

  1. MFC New Bee

    MFC New Bee New Member

    Joined:
    Dec 9, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi all,
    I am creating an application named 'BmpViewer' in which the user can view the bitmap , copy the bitmap on the new file , save the bitmap as normal or black and white . Also a provision is to be given to view the bitmap in different modes of colours, like red, blue, green and gray.So far i have read the bmp file but i have no idea about how to display the image without using the HBITMAP. Below is my code.
    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);
     int nNoOfPalette = pow(double(2) , double(m_bmiInfoHead.biBitCount));
     if(m_bmiInfoHead.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.biWidth)    * 
            ((DWORD)m_bmiInfoHead.biBitCount)) *
           m_bmiInfoHead.biHeight;
                       
     m_bmBits = new BYTE[nSize];
     fread(&m_bmBits , sizeof(m_bmBits) , 1 , fp);
     m_bFlag = TRUE;
     return TRUE;
    }
    
    Could any one suggest me a way of displaying the image.

     
    Last edited by a moderator: Dec 10, 2010

Share This Page