256色图。竟然是2色的。windows xp下编译
char* bitmapinfohead=new char[256*sizeof(RGBQUAD)+sizeof(BITMAPINFOHEADER)];
BITMAPINFOHEADER* phead=(BITMAPINFOHEADER*)bitmapinfohead;
phead->biSize=sizeof(BITMAPINFOHEADER);
phead->biWidth=m_shortWidth;
phead->biHeight=-m_shortHeight;
phead->biPlanes=1;
phead->biBitCount=8;
phead->biCompression=BI_RGB;
phead->biSizeImage=0;
phead->biXPelsPerMeter=0;
phead->biYPelsPerMeter=0;
phead->biClrUsed=255;
phead->biClrImportant=255; RGBQUAD* prgb=(RGBQUAD*)(bitmapinfohead+sizeof(BITMAPINFOHEADER));
for(int i=0;i<256;i++)
{
prgb->rgbRed=m_colormap[i][0];//m_colormap256种色表
prgb->rgbGreen=m_colormap[i][1];
prgb->rgbBlue=m_colormap[i][2];
prgb->rgbReserved=0;
prgb++;
} if(m_hDC==NULL)
{
HDC hdc=GetDC(m_hwnd);
m_hDC=::CreateCompatibleDC(hdc);
ReleaseDC(m_hwnd,hdc);
} m_hBitmap=::CreateDIBitmap(m_hDC,                        // handle to DC
phead, // bitmap data
CBM_INIT, 
m_pScreenBuffer, // 位图数据。256色
(BITMAPINFO*)phead,           
DIB_RGB_COLORS);
HBITMAP temp=(HBITMAP)::SelectObject(m_hDC,m_hBitmap);
int bits=GetDeviceCaps(m_hDC,BITSPIXEL);
if(temp!=NULL) ::DeleteObject(temp);
RGBQUAD test[256];
int setcolors=SetDIBColorTable(
m_hDC,               // handle to DC
0,      // color table index of first entry
256,         // number of color table entries
((BITMAPINFO*)phead)->bmiColors // array of color table entries
        //setcolors返回0;
);
int colors=GetDIBColorTable(m_hDC,           // handle to DC
0,  // color table index of first entry
256,     // number of entries to retrieve
test   // array of color table entries
);//color 返回2
delete []bitmapinfohead;
return 0;

解决方案 »

  1.   

    为什么不用LoadImage()直接读取显示!
    HBITMAP hbmp=(HBITMAP)LoadImage("",,,,);
    CBitmap bmp,*pold;
    bmp.Attach(hbmp);
    CDC dcmem;
    dcmem.CreateCompatibleDC(NULL);
    pold=dcmem.SelectObject(&bmp);
    //如果想得到图像的其他信息
    BITMAP m_bmp;
    bmp.GetObject(sizeof(m_bmp),&m_bmp);
    CClientDC dc(this);
    dc.Bitblt()
    dcmem.SelectObject(pold);
    dcmem.DeleteDC();
    bmp.DeleteObject();
      

  2.   

    ....
    if(m_hDC==NULL)
    {
    HDC hdc=GetDC(m_hwnd);
    m_hDC=::CreateCompatibleDC(hdc);
    ReleaseDC(m_hwnd,hdc);
    } m_hBitmap=::CreateDIBitmap(m_hDC,                        // handle to DC
    .....将
    m_hBitmap=::CreateDIBitmap(m_hDC,                        // handle to DC
    改为
    m_hBitmap=::CreateDIBitmap(hDC,                        // handle to DC
      

  3.   


    m_hBitmap=::CreateDIBitmap(hdc,                        // handle to DC