【发布时间】:2016-03-04 19:36:47
【问题描述】:
关于
我正在使用 WinForms。在我的表单中,我有一个打开和打印按钮。打开按钮将 tif 图像打开到图片框中。打印按钮从图片框中打印这些图片。我使用大图像文档,例如宽度和长度:(3000, 3600)。所以我缩放了这些 tif 图像文档以适合常规打印纸尺寸 (8.5 x 11)。我这样做的原因是使用下面的方法,tif 图像上的字母不会模糊。
问题
好消息是它可以很好地缩放,这意味着它并不模糊。坏消息是它的规模缩小了很多。见图 A.2
测试
测试 i 增加和减少 *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
-
您能否提供指向您正在使用的 pageViewer.Image 中的实际图像的链接?
-
我可以提供一个链接,让我做那个
-
该图像的文本周围有一个厚厚的白色边框。使用 e.PageBounds 代替 e.MarginBounds 并再次回到 0, 0 位置打印。
标签: c# .net image winforms printing