有了阿?
memcpy(&(m_lpbyteBi.bmiColors),&(m_lpBi->bmiColors),sizeof(RGBQUAD));

解决方案 »

  1.   

    有了阿?
    memcpy(&(m_lpbyteBi.bmiColors),&(m_lpBi->bmiColors),sizeof(RGBQUAD));======================================================1 bit的调色板(如果有的话)和 8 bits的调色板大小是一样的吗?难怪会是黑色的了。
      

  2.   

    hDc=CreateCompatibleDC(NULL);
    hbyteDc=CreateCompatibleDC(NULL);
    SelectObject(hDc, m_hBitmap);
    SelectObject(hbyteDc, m_hbyteBitmap);
    memset(colortable,0,1024);
    GetDIBColorTable(hDc, 0, 2, colortable);
    SetDIBColorTable(hbyteDc, 0, 256, colortable);
    DeleteDC(hbyteDc);
    DeleteDC(hDc);

    加上了颜色表处理,图像怎么变形了?
    代码见下:
    1bit->8bit:其中m_lpBi,m_lpbuf 是原始图像的信息和图像数据;
    void CTestBitDoc::On1To8() 
    {
    // TODO: Add your command handler code here
    int i,j,k,m,ln;
    char *tmp_fbuf;
    char* pbyte;
    FILE* fp;
    BITMAPFILEHEADER BFH;
    FILE *fp1;
    int BmSize;
    RGBQUAD colortable[256];
    HDC hDc,hbyteDc;
    m_lpbyteBi=(LPBITMAPINFO)malloc(40+4*256);
    memcpy(m_lpbyteBi, m_lpBi, 40);
    m_lpbyteBi->bmiHeader.biBitCount = 8;
    m_lpbyteBi->bmiHeader.biSizeImage = m_lpBi->bmiHeader.biWidth*m_lpBi->bmiHeader.biHeight;


    m_hbyteBitmap=CreateDIBSection(NULL,m_lpbyteBi,DIB_RGB_COLORS,(void**)&m_lpnbuf,NULL,0);
    hDc=CreateCompatibleDC(NULL);
    hbyteDc=CreateCompatibleDC(NULL);
    SelectObject(hDc, m_hBitmap);
    SelectObject(hbyteDc, m_hbyteBitmap);
    memset(colortable,0,1024);
    GetDIBColorTable(hDc, 0, 2, colortable);
    SetDIBColorTable(hbyteDc, 0, 256, colortable);
    DeleteDC(hbyteDc);
    DeleteDC(hDc);


    pbyte=(char*)malloc(m_lpBi->bmiHeader.biHeight*m_lpBi->bmiHeader.biWidth);


    tmp_fbuf=pbyte;
    for(i=m_lpBi->bmiHeader.biHeight; i>0; i--)
    {
    ln=0;
    for(j=0; j<((m_lpBi->bmiHeader.biWidth*m_lpBi->bmiHeader.biBitCount+31)/32*4); j++)
    {
    for(k=0,m=0x80; k<8; k++)
    {
    if(ln<m_lpBi->bmiHeader.biWidth)
    {

    *tmp_fbuf=(*m_lpbuf) & m;
    tmp_fbuf++;
    }
    ln++;
    m=m>>1;
    }
    m_lpbuf++;
    }
    }


    memcpy(m_lpnbuf, pbyte, m_lpbyteBi->bmiHeader.biSizeImage);
    free(pbyte);
    fclose(fp);

    UpdateAllViews(NULL);
    }
      

  3.   

    LPRGBQUAD           lpColor;
    int nColors = 256*sizeof(RGBQUAD);
    lpColor = new RGBQUAD[256];
    memset(lpColor, 0, nColors);
    for(int i = 0; i < 256; i ++)
    {
    lpColor[i].rgbBlue  = i;
    lpColor[i].rgbGreen = i;
    lpColor[i].rgbRed   = i;
    }