为什么 GDI DrawString 调用在 PrintDocument 中与渲染到图像中的行为不同?
我正在使用 PrintDocument 类在 C# 中开发打印应用程序。我已经让物理打印部分按照我想要的方式工作,但要求之一是我还保存图像文件。
我创建了一个图像并使用渲染打印页面的相同 GDI 调用。除了文字之外,它看起来很接近。打印的页面很好,但保存的图像导致 8pt Courier 字体显示为 0.1pt 字体。
我尝试添加以下内容,但没有成功:
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
关于文本渲染为何存在差异的任何想法?
I am working on a printing application in C# using the PrintDocument class. I have gotten the physical printing part working the way I want, but one of the requirements is that I save an image file as well.
I have created an image and use the same GDI calls that rendered the printed page. It looks pretty close except for the text. The printed page is fine, but the saved image is causing the 8pt Courier font to show up as what appears to be a 0.1pt font.
I have tried adding the following, with no luck:
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
Any ideas as to why the difference in text rendering?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有足够的代码可供查看,发布的代码片段与字体缩放无关。
打印页面和图像之间的最大区别在于分辨率的巨大差异。通常为 600 dpi 与 96 dpi。打印机的默认缩放比例为 1 像素 = 0.01 英寸,使得文本和图像在渲染到屏幕和纸张上时几乎具有相同的尺寸。更改缩放比例会导致您遇到的麻烦。
例如,在代码中查找对 Graphics.PageUnit 的任何分配。
Not enough code to look at, the posted snippets are not relevant to font scaling.
The big difference between a printed page and an image is the drastic difference in resolution. 600 dpi vs 96 dpi, typically. Default scaling for the printer is 1 pixel = 0.01 inch, making text and images almost the same size when rendered to the screen vs paper. Changing that scaling causes the kind of trouble you're having.
Look for any assignments to Graphics.PageUnit in your code, for example.