c++ - 使用 GDI+ 打印位图失真
问题描述
所以我正在尝试打印一页文档。我基本上是在页面大小的位图上绘制文本和 blting 位图,然后在打印机的 DC 上 blting 那个位图
nPixWidth = 5100
并且nPixHeight = 6600
,那么 445 x 1092 位图如何占据页面的整个顶部?比如,到底是什么?我在这里想念什么?
我不必使用 GDI+。我可以使用DrawText
and BitBlt
or 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;
解决方案
推荐阅读
- html - 在 css 中将文本包装成 svg 形状(Indesign 样式)
- javascript - 更新具有匹配属性的对象并忽略新属性
- java - SWAGGER swagger-codegen 配置
- amazon-web-services - 我可以在多个实例上使用 aws cloudwatch 日志吗?
- arrays - 更新mongodb数组中的多个元素
- protractor - 量角器:无法处理基于窗口的弹出窗口以使用量角器框架浏览和上传文件
- vb.net - 获取文件夹中的文件,另一个文件夹中的文件?
- groovy - SoapUI Groovy - 使用 json slurper 对象过滤器提取子节点
- javascript - JavaScript 没有正确比较
- php - 如何让 PHP bot 打印标题