从数据库中读出了BMP数据存入(char*)szPhoto中。在不写硬盘文件的情况下,怎样生成该位图的HBITMAP?

解决方案 »

  1.   

    CreateDIBitmap
    The CreateDIBitmap function creates a compatible bitmap (DDB) from a DIB and, optionally, sets the bitmap bits. HBITMAP CreateDIBitmap(
      HDC hdc,                        // handle to DC
      CONST BITMAPINFOHEADER *lpbmih, // bitmap data
      DWORD fdwInit,                  // initialization option
      CONST VOID *lpbInit,            // initialization data
      CONST BITMAPINFO *lpbmi,        // color-format data
      UINT fuUsage                    // color-data usage
    );
      

  2.   

    CDC *dc=new CDC;
    dc->CreateCompatibleDC(NULL); int nBitCount = GetDeviceCaps(dc->m_hDC,BITSPIXEL); LPBITMAPINFO lpBitmap;
    lpBitmap=(BITMAPINFO*) new BYTE[sizeof(BITMAPINFOHEADER) + 
        GetColorNumber(nBitCount) * sizeof(RGBQUAD)];

    lpBitmap->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
    lpBitmap->bmiHeader.biWidth=320;
    lpBitmap->bmiHeader.biHeight=240;
    lpBitmap->bmiHeader.biBitCount=nBitCount;
    lpBitmap->bmiHeader.biPlanes=1;
    lpBitmap->bmiHeader.biCompression=BI_RGB;
    lpBitmap->bmiHeader.biSizeImage=0;
    lpBitmap->bmiHeader.biClrUsed=0;
    HBITMAP hBitmap=::CreateDIBSection(dc->m_hDC,lpBitmap,DIB_RGB_COLORS,&m_szPhoto,NULL,0);
    帮我看看哪里错了
      

  3.   

    http://www.shineblog.com/user1/6589/archives/2005/62556.shtml看看这个文章,对BMP的存贮格式有详细说明。