最近一直困扰我的问题

来源:互联网 发布:计算机算法流程图 编辑:程序博客网 时间:2024/05/01 15:00

 

在vc2005中做在对话框中显示bmp图像的程序,以下是源码:有些大的图像只能显示下面1/3,而用mfc 的CFile 和C语言的FILE都没有问题不知道怎么回事,现在不敢用STL的流了。
//全局变量
    BITMAPFILEHEADER header;
    BITMAPINFOHEADER infoheader;
      ifstream inf;
    int iLineByteCnt ;
    int m_iImageDataSize;
    int m_iImageWidth;
    int m_iImageHeight;
    int m_iBitsPerPixel;
    char* m_pImageData;
    char*pDib;
//文件处理函数
void CBMPDlg::OnBnClickedButton1()
{


        inf.open("E://yang.bmp");
        memset(&header, 0, sizeof(header));
        inf.read((char*)&header, sizeof(header));
        if(header.bfType != 0x4D42)
                  return ;
                 
        BITMAPINFOHEADER *infoheader;
        pDib=new char[ header.bfSize-sizeof(header)];
        inf.read(pDib, header.bfSize-sizeof(header));
        infoheader=(BITMAPINFOHEADER*)pDib;//关于语法
        m_iImageWidth = infoheader->biWidth;
        m_iImageHeight = infoheader->biHeight;
        m_iBitsPerPixel = infoheader->biBitCount;


        iLineByteCnt =(((m_iImageWidth*m_iBitsPerPixel) + 31) >> 5) < < 2;
        m_iImageDataSize = header.bfSize-header.bfOffBits;
        iLineByteCnt=m_iImageDataSize/m_iImageHeight;
        if(m_pImageData) delete []m_pImageData;
        m_pImageData  =pDib+infoheader->biSize;


        inf.close();
          BITMAPINFO bmi;
            memset(&bmi, 0, sizeof(bmi));
            bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
            bmi.bmiHeader.biWidth = m_iImageWidth;
            bmi.bmiHeader.biHeight = m_iImageHeight;
            bmi.bmiHeader.biPlanes = 1;
            bmi.bmiHeader.biBitCount = 24;
            bmi.bmiHeader.biCompression = BI_RGB;
            bmi.bmiHeader.biSizeImage = m_iImageDataSize;
 

StretchDIBits(this->GetDC()->GetSafeHdc(), 0, 0, m_iImageWidth,  m_iImageHeight,
0, 0, m_iImageWidth, m_iImageHeight,  m_pImageData,&bmi, DIB_RGB_COLORS, SRCCOPY);

}

原创粉丝点击