首页 > 解决方案 > 使用 GDI+ 打印位图失真

问题描述

所以我正在尝试打印一页文档。我基本上是在页面大小的位图上绘制文本和 blting 位图,然后在打印机的 DC 上 blting 那个位图

nPixWidth = 5100并且nPixHeight = 6600,那么 445 x 1092 位图如何占据页面的整个顶部?比如,到底是什么?我在这里想念什么?

我不必使用 GDI+。我可以使用DrawTextand BitBltor StretchBlt,但我认为 GDI+ 会更好。

    int nPixWidth = GetDeviceCaps(m_hPrinterDC, PHYSICALWIDTH), nPixHeight = GetDeviceCaps(m_hPrinterDC, PHYSICALHEIGHT);
    int nPixMarginWidth = GetDeviceCaps(m_hPrinterDC, PHYSICALOFFSETX), nPixMarginHeight = GetDeviceCaps(m_hPrinterDC, PHYSICALOFFSETY);
//  int nDPI = nPixHeight / GetDeviceCaps(m_hPrinterDC, )
    Bitmap myBitmap(nPixWidth - nPixMarginWidth, nPixHeight - nPixMarginHeight, PixelFormat32bppARGB);
    HBITMAP hLogoBmp = (HBITMAP)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP_THELOGO_HORZ), IMAGE_BITMAP, 0, 0, 0);  // 445 x 1092
    GetPaperDimensions(m_cReportOptions.m_devMode.dmPaperSize, m_fPageWidth, m_fPageHeight);
    Graphics printer(m_hPrinterDC); 
    Graphics page(&myBitmap);
    Bitmap *pBmpLogo = Bitmap::FromHBITMAP(hLogoBmp, NULL);
    int nLogoWidth = pBmpLogo->GetWidth(), nLogoHeight = pBmpLogo->GetHeight();
    SolidBrush whiteBrush(Color(255, 255, 255));
    page.FillRectangle(&whiteBrush, 0, 0, nPixWidth - nPixMarginWidth, nPixHeight - nPixMarginHeight);
    page.DrawImage(pBmpLogo, 0, 0, nLogoWidth, nLogoHeight);
    printer.DrawImage(&myBitmap, 0, 0); // , (INT)nPixWidth, (INT)nPixHeight);
    DeleteObject(hLogoBmp);
    delete pBmpLogo;

标签: c++windowsvisual-c++printingmfc

解决方案


推荐阅读