我要打印一个饼图,放在剪贴板里,打印预览已经看到了该饼图,但是为啥不能打印出该饼图?
饼图颜色是彩色,打印机是单色

解决方案 »

  1.   

    CWnd::Print
    void Print( CDC* pDC, DWORD dwFlags ) const;
      

  2.   

    我问的就是你在OnDraw中通过什么dc成员函数画上去的饼图
      

  3.   

    pDC->SetMapMode( MM_TEXT);  //pDC是 void CStatListView::OnDraw(CDC* pDC)
    if(m_hbitmap)               //m_hbitmap是剪切下来的位图
    {
                  BITMAP bm;
             ::GetObject(m_hbitmap, sizeof(BITMAP), &bm);
              CSize chartSize(bm.bmWidth, bm.bmHeight);        CDC dcMemory,dcScreen;
            dcScreen.Attach(::GetDC(NULL));
     
         // create "from" device context and select the loaded bitmap into it
         dcMemory.CreateCompatibleDC(&dcScreen);
         dcMemory.SelectObject(p->m_hbitmap);

             // Print at 85% size within left/right margin 
                  CSize printSize;
            printSize.cx=(int)(rectPage.right*.85);
            
    printSize.cy=printSize.cx/chartSize.cx*chartSize.cy;
    CRect rect(0,0,printSize.cx,printSize.cy); // Print chart centered
    pDC->StretchBlt(500 ,rectPage.bottom-printSize.cy, printSize.cx, printSize.cy, &dcMemory, 0, 0, chartSize.cx, chartSize.cy, SRCCOPY);
    dcMemory.DeleteDC();
      }
    }
      

  4.   

    可能是原點位置不對.所以看不到圖像.
    SetViewportOrg(0,500)或是其它值試試.也可以把y坐標改為負數試試
      

  5.   

    在啥地方放置SetViewportOrg(0,500)
      

  6.   

    StretchBlt之前先用pDC->GetDeviceCaps(RASTERCAPS);看一下支不支持RC_STRETCHBLT
      

  7.   

    pDC->SetMapMode( MM_TEXT); 后面
      

  8.   

    我加上测试 int xy=pDC->GetDeviceCaps(RASTERCAPS);
    if(xy==RC_STRETCHBLT)
                 MessageBox("op");
    不显示op,是否表明不支持StretchBlt,我该如何改程序
      

  9.   

    pDC->SetMapMode( MM_TEXT); 后面
    是啥意思,如何改
      

  10.   

    if((xy&RC_STRETCHBLT)==RC_STRETCHBLT)
      

  11.   

    薄荷,我测试过了,if((xy&RC_STRETCHBLT)==RC_STRETCHBLT)
    是成立的,表明支持StretchBlt为啥打印预览已经看到了该饼图,不能打印出该饼图?奇怪!
      

  12.   

    还有不知道你if((xy&RC_STRETCHBLT)==RC_STRETCHBLT)是不是在打印而不是在预览下返回真的
      

  13.   

    现在我知道了,不知道你还有没有兴趣听,主要原因是你的位图是DDB,和打印设备不兼容,你要把它转化成DIB位图,通过StretchDIBits打印
    下面是一些转化和打印的代码
    void Draw(HDC hDC,HBITMAP hBmp,double dScaleX,double dScaleY,int iX,int iY,int iWidth=0,int iLength=0)
    {
    HPALETTE hPal;
    BITMAP bm;
    BITMAPINFOHEADER bi;
    LPBITMAPINFOHEADER  lpbi;
    DWORD dwLen;
    HANDLE hDIB;
    HANDLE handle;
    HDC  hDC1;
    if(GetDeviceCaps(hDC,RASTERCAPS) & RC_PALETTE )
    {
    UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256);
    LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];
    pLP->palVersion = 0x300;
    pLP->palNumEntries =GetSystemPaletteEntries( hDC, 0, 255, pLP->palPalEntry );
    hPal=CreatePalette(pLP );
    delete[] pLP;
    }
    if (hPal==NULL) hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);
    ::GetObject(hBmp,sizeof(bm),(LPSTR)&bm);
    bi.biSize = sizeof(BITMAPINFOHEADER);
    bi.biWidth = bm.bmWidth;
    bi.biHeight  = bm.bmHeight;
    bi.biPlanes  = 1;
    bi.biBitCount = bm.bmPlanes * bm.bmBitsPixel;
    bi.biCompression = BI_RGB;
    bi.biSizeImage = 0;
    bi.biXPelsPerMeter = 0;
    bi.biYPelsPerMeter = 0;
    bi.biClrUsed = 0;
    bi.biClrImportant = 0;
    int nColors = (1 << bi.biBitCount);
    if( nColors > 256 )
    nColors = 0;
    dwLen  = bi.biSize + nColors * sizeof(RGBQUAD);
    hDC1 = ::GetDC(NULL);
    hPal = SelectPalette(hDC1,hPal,FALSE);
    RealizePalette(hDC1);
    hDIB = GlobalAlloc(GMEM_FIXED,dwLen);
    if (!hDIB)
    {
    SelectPalette(hDC1,hPal,FALSE);
    ::ReleaseDC(NULL,hDC1);
    DeleteObject(hPal);
    return ;
    }
    lpbi = (LPBITMAPINFOHEADER)hDIB;
    *lpbi = bi;
    ::GetDIBits(hDC1, hBmp, 0L, (DWORD)bi.biHeight,
    (LPBYTE)NULL, (LPBITMAPINFO)lpbi, (DWORD)DIB_RGB_COLORS);
    bi = *lpbi;
    if (bi.biSizeImage == 0)
    bi.biSizeImage = ((((bi.biWidth * bi.biBitCount) + 31) & ~31) / 8)* bi.biHeight;
    dwLen += bi.biSizeImage;
    if (handle = GlobalReAlloc(hDIB, dwLen, GMEM_MOVEABLE))
    hDIB = handle;
    else
    {
    GlobalFree(hDIB);
    SelectPalette(hDC1,hPal,FALSE);
    ::ReleaseDC(NULL,hDC1);
    DeleteObject(hPal);
    return ;
    }
    lpbi = (LPBITMAPINFOHEADER)hDIB;
    BOOL bGotBits = GetDIBits( hDC1, hBmp,0L,(DWORD)bi.biHeight,(LPBYTE)lpbi+ (bi.biSize + nColors * sizeof(RGBQUAD)),
    (LPBITMAPINFO)lpbi,(DWORD)DIB_RGB_COLORS);
    if( !bGotBits )
    {
    GlobalFree(hDIB);
    SelectPalette(hDC1,hPal,FALSE);
    ::ReleaseDC(NULL,hDC1);
    DeleteObject(hPal);
    return;
    }
    if(iWidth==0||iLength==0)
    {
    iWidth=lpbi->biWidth;
    iLength=lpbi->biHeight;
    iWidth=(int)(dScaleX*iWidth);
    iLength=(int)(iLength*dScaleY);
    }
    StretchDIBits(hDC,iX,iY,iWidth,iLength,0,0,lpbi->biWidth,lpbi->biHeight,(LPBYTE)lpbi  // address for bitmap bits
    + (bi.biSize + nColors * sizeof(RGBQUAD)),(LPBITMAPINFO)lpbi,DIB_RGB_COLORS,SRCCOPY);
    SelectPalette(hDC1,hPal,FALSE);
    ::ReleaseDC(NULL,hDC1);
    DeleteObject(hDIB);
    DeleteObject(hPal);
    }