关于
我正在使用WinForms。在我的窗体中,有一个“打开”按钮和一个“打印”按钮。点击“打开”按钮会将tif图像打开到一个picturebox中。点击“打印”按钮会从picturebox中打印这些图片。我处理大型图像文档,例如宽度和长度:(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.Graphics.DrawImage(i, e.MarginBounds.Left, e.MarginBounds.Top, (int)newWidth, (int)newHeight);
。 - LarsTech