因此,我正在尝试打印一页文档。我基本上是在绘制文本,然后将位图涂抹到页面大小的位图上,然后在打印机的DC上涂抹该位图
nPixWidth = 5100
和nPixHeight = 6600
,那么位图445 x 1092如何占据页面的整个顶部?像,到底是什么?我在这里想念什么?
我不必使用GDI +。我可以使用DrawText
和BitBlt
或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;