关于
我正在使用 WinForms。在我的表单中,我有一个打开和打印按钮。打开按钮将 tif 图像打开到图片框中。打印按钮从图片框中打印这些图片。我使用大图像文档,例如宽度和长度:(3000, 3600)。所以我缩放了这些 tif 图像文档以适合常规打印纸尺寸 (8.5 x 11)。我这样做的原因是使用下面的方法 tif 图像上的字母不会模糊。
问题
好消息是它缩放得很好,这意味着它不模糊。坏消息是它缩小了很多。见图A.2
测试
测试我增加和减少了 * 100 奇怪的是它没有增加大小但减少了大小
float newWidth = i.Width * 100 / i.HorizontalResolution; float newHeight = i.Height * 100 / i.VerticalResolution;
代码
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{ //pageViewer = picturebox
Image i = pageViewer.Image;
float newWidth = i.Width * 100 / i.HorizontalResolution;
float newHeight = i.Height * 100 / i.VerticalResolution;
float widthFactor = newWidth / e.MarginBounds.Width;
float heightFactor = newHeight / e.MarginBounds.Height;
if (widthFactor > 1 | heightFactor > 1)
{
if (widthFactor > heightFactor)
{
newWidth = newWidth / widthFactor;
newHeight = newHeight / widthFactor;
}
else
{
newWidth = newWidth / heightFactor;
newHeight = newHeight / heightFactor;
}
}
e.Graphics.DrawImage(i, 0, 0, (int)newWidth, (int)newHeight);
}
它应该如何打印
最佳答案
您的图像已经包含边距,因此当您使用 e.MarginBounds 属性时,实际上是将边距加倍。要修复,请改用 PageBounds 属性。
float widthFactor = newWidth / e.PageBounds.Width;
float heightFactor = newHeight / e.PageBounds.Height;
关于c# - 打印适合纸张 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35804663/