解决方案 »

  1.   

    谢谢指点,不过还是不懂,那具体通过修改哪些参数可以改善呢?是文件头信息结构体重的参数?还是m_nBmpWidth =mybitmap.GetWidth();??
      

  2.   

    我的位图文件头信息设置如下:
    BITMAPINFO* pInfo = (BITMAPINFO*)malloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));//分配空间
    BITMAPINFOHEADER Info_Header;     

    Info_Header.biSize = sizeof(BITMAPINFOHEADER);
    Info_Header.biWidth = nBmpWidth;
    Info_Header.biHeight = nBmpHeight;
    Info_Header.biPlanes = 1;
    Info_Header.biBitCount = 24;
    Info_Header.biCompression = BI_RGB;
    Info_Header.biSizeImage = nBmpHeight * nBmpWidth*3;                        
    Info_Header.biXPelsPerMeter = 0;
    Info_Header.biYPelsPerMeter = 0;
    Info_Header.biClrUsed  = 0;
    Info_Header.biClrImportant = 0;

    for(int i=0;   i<256;   i++)   
    {   
    pInfo->bmiColors[i].rgbBlue  =   (BYTE)i;   
    pInfo->bmiColors[i].rgbGreen =   (BYTE)i;   
    pInfo->bmiColors[i].rgbRed   =   (BYTE)i;   
    pInfo->bmiColors[i].rgbReserved = 0;   
    }

    memcpy(pInfo, &Info_Header, sizeof(BITMAPINFOHEADER));

    return pInfo;
      

  3.   

    256 * sizeof(RGBQUAD)
    能确定 调色板是 256 项 吗 ?
      

  4.   

    void CMyImageDlg::GetNewBitmap()
    {
    Bitmap myBitmap(L"Myimage2.jpg"); // 57,858 字节
    m_nBmpWidth = myBitmap.GetWidth();// 650
    if(m_nBmpWidth==0) return;
    //
    m_nBmpHeight=myBitmap.GetHeight();// 600
    if(m_nBmpHeight==0) return;
    //
    Color backColor;//  Argb 0xff000000
    myBitmap.GetHBITMAP(backColor, &m_hBitmap);
    if(m_hBitmap ==0 ) return;
    //
    PixelFormat pf=myBitmap.GetPixelFormat();
    if(pf == PixelFormat24bppRGB)
    {
    afxDump << "The pixel format of is 24bppRGB.\n";
    }
    ...格式  PixelFormat24bppRGB
    应该没有调色板.
      

  5.   

    不知道你的目的,下面是上下颠倒的代码:void CMyImageDlg::GetNewBitmap()
    {
    Bitmap myBitmap(L"Myimage2.jpg"); // 57,858 字节
    m_nBmpWidth = myBitmap.GetWidth();// 650
    if(m_nBmpWidth==0) return;
    //
    m_nBmpHeight=myBitmap.GetHeight();// 600
    if(m_nBmpHeight==0) return;
    // check format
    PixelFormat pf=myBitmap.GetPixelFormat();
    if(pf != PixelFormat24bppRGB) return;
    // make new 
    Bitmap *pBitmap=myBitmap.Clone(0,0,m_nBmpWidth,m_nBmpHeight,pf);
    // upside down !
    Color mycolor;
    for(int i = 0; i < m_nBmpHeight; i++)
    {
    for(int j = 0; j < m_nBmpWidth; j++)//x--width
    {
    myBitmap.GetPixel(j,i,&mycolor);//获得像素值
    pBitmap->SetPixel(j,m_nBmpHeight-1-i,mycolor);
    }
    }
    // for paint
    Color backColor; //  Argb 0xff000000
    pBitmap->GetHBITMAP(backColor, &m_hBitmap);
    if(m_hBitmap ==0 ) return;
    }
    //////////////////////////////////
    void CMyImageDlg::OnPaint() 
    ......
    else
    {
    CPaintDC dc(this); // device context for painting
    if(m_hBitmap)
    {
    CDC memDC;
    memDC.CreateCompatibleDC(&dc);
    HBITMAP hold=(HBITMAP)memDC.SelectObject(m_hBitmap);
    CRect rc;
    GetClientRect(&rc);
    dc.SetStretchBltMode(HALFTONE);
    dc.StretchBlt(rc.left,rc.top,rc.Width(),rc.Height(),&memDC,
              0,0,m_nBmpWidth,m_nBmpHeight,SRCCOPY);
    // free
    memDC.SelectObject(hold);
    }