最近一直困扰我的问题

 

在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);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值