我是vc++的初学者,想要用vc++实现对bmp图片的读入,可是不知道怎么实现,请高手帮忙!谢谢~~

解决方案 »

  1.   

    LoadImage();
    这样的贴子很多,查下以前的贴子
      

  2.   

    BITMAPFILEHEADER* m_pBMFH;
    BITMAPINFOHEADER* m_pBMIH;
    BOOL bIsok=false;
    if (NULL==pFileData) 
    {
    CPicture cp;
    btmap=cp.ReadPict(pBmpName);
    if (btmap==NULL)
    {
    MessageBox(hwnd,pBmpName,"无法读取",0);
    return false;
    }
    }
    m_pBMFH = (BITMAPFILEHEADER*)pFileData;
    if((pFileData[0]!='B')||(pFileData[1]!='M'))
        {
    MessageBox(hwnd,"无法识别的文件格式","错误提示",0);
    return FALSE;
        }
        m_pBMIH = (BITMAPINFOHEADER*)(pFileData+sizeof(BITMAPFILEHEADER));
        if(m_pBMIH->biSize!=sizeof(BITMAPINFOHEADER))
    {
    MessageBox(hwnd,"无法识别的格式","错误提示",0);
    return FALSE;
    }
    HDC hdc=GetDC(hwnd);
    ULONG bfoffBits= 0;
    bfoffBits=m_pBMFH->bfOffBits;
    if (btmap==NULL)
    btmap=CreateDIBitmap(hdc,m_pBMIH,CBM_INIT,pFileData+bfoffBits,
    (LPBITMAPINFO)m_pBMIH,DIB_RGB_COLORS); 

    if (NULL==btmap) 
    {
    DWORD errcode = GetLastError();
    char buffer[20];
    _ltoa(errcode,buffer,10);
    MessageBox(hwnd,buffer,"err",0);
    return false;
    } RECT crect;
    HDC hMemdc;
    GetClientRect(hwnd,&crect);
    hMemdc=CreateCompatibleDC(hdc);
    SetDIBits(hdc,btmap,0,500,pFileData,(BITMAPINFO*)&m_pBMIH,DIB_RGB_COLORS); SelectObject(hMemdc,btmap);

    StretchBlt(hdc,crect.left,crect.top,crect.right - crect.left
    ,crect.bottom - crect.top,hMemdc,crect.left,crect.top,
    m_pBMIH->biWidth,m_pBMIH->biHeight,SRCCOPY);
    //BitBlt(hdc,crect.left,crect.top,crect.right - crect.left
    // ,crect.bottom - crect.top,hMemdc,
    // crect.left,crect.top,SRCCOPY);


    DeleteDC(hMemdc);
    ReleaseDC(hwnd,hdc);


    return true;
    }