入门有关问题:图像打开

入门问题:图像打开
我工程中添加的是已写好Imag.h ,Imag.cpp。,类中也包含了打开图像的函数,为什么运行的时候却打开不了

------解决方案--------------------
贴出你的CPP文件中是如何引用 头文件的代码,就好判断了
------解决方案--------------------
现在是什么错误啊?还是不报告错误?
------解决方案--------------------
直接使用CImage类就可以了~
------解决方案--------------------
bmfHeader.bfOffBits - sizeof。。。
bmp 通常是从文件头 往下(即 + sizeof)
你怎么是从下到上,bmfHeader.bfOffBits 能保证对吗?
------解决方案--------------------
C/C++ code

BYTE * OpenBMP(CString fileName, int *width, int *height)
{
    BYTE * pData, * pData1;
    if(fileName=="")
        return NULL;

    BITMAPFILEHEADER bmpFileHead;
    BITMAPINFOHEADER bmpInfo;

    CFile file;
    if((file.Open(fileName,CFile::modeRead|CFile::shareDenyNone))==NULL)
    {
        AfxMessageBox("Can not open the file");
        return NULL;
    }
 
    file.SeekToBegin();

    file.Read(&bmpFileHead,sizeof(BITMAPFILEHEADER));
    file.Read(&bmpInfo,sizeof(BITMAPINFOHEADER));
    DWORD LineBytes=(DWORD)WIDTHBYTES(bmpInfo.biWidth*bmpInfo.biBitCount);
    DWORD ImageSize =(DWORD)LineBytes*bmpInfo.biHeight;
    int NumColors;
    if(bmpInfo.biClrUsed!=0)
       NumColors=(DWORD)bmpInfo.biClrUsed;
    else
        switch(bmpInfo.biBitCount){
        case 1:
            NumColors=2;
            break;
        case 4:
            NumColors=16;
            break;
        case 8:
            NumColors=256;
            break;
        case 24:
            NumColors=0;
            break;
        default:
            AfxMessageBox("Invalid color numbers!");
            file.Close();
            return NULL;
    }

    if(bmpFileHead.bfOffBits!=(DWORD)(NumColors*sizeof(RGBQUAD)+sizeof(BITMAPFILEHEADER)
                            +sizeof(BITMAPINFOHEADER)))
    {
            
        AfxMessageBox("offBits 和实际头长度不符");
        //    ,"Error Message" ,MB_OK|MB_ICONEXCLAMATION);
        return NULL; 
    }

    pData = (BYTE*)new char[ImageSize];
    pData1 = (BYTE*)new char[ImageSize*3/2];
    file.Seek(sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+NumColors*sizeof(RGBQUAD),SEEK_SET);
    file.Read(pData,ImageSize);
    *width = bmpInfo.biWidth;
    *height = bmpInfo.biHeight;

    file.Close();

    int h,w;
    h=*height;
    w=*width;
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
                {
                BYTE * temp;
                temp=pData+(h-1-i)*w+j;
                pData1[i*w+j]=*temp;
                }
        }
    if(pData) delete pData;
    memset(pData1+ImageSize,128,ImageSize/2);
     return pData1;
    free(pData1);

}