2016-03-04 154 views
1

关于

我正在使用WinForms。在我的表单中,我有一个打开和打印按钮。 Open按钮将tif图像打开成一个picturebox。打印按钮从图片框打印这些图片。我使用大图像文件,例如宽度和长度:(3000,3600)。所以我缩放这些tif图像文件以适应常规打印纸张尺寸(8.5 x 11)。我这样做的原因是,使用下面的方法,tif图像上的字母不会模糊。
打印适合纸张C#

问题

可喜的是它缩放的意思是很好的不模糊。坏消息是缩小到很多。见图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); 
     } 


其如何想打印

enter image description here

它是如何正在打印 图A.2 enter image description here

+1

代码似乎工作,除非你在边缘打印。尝试'e.Graphics.DrawImage(我,e.MarginBounds.Left,e.MarginBounds.Top,(int)newWidth,(int)newHeight);' – LarsTech

+0

我现在测试了这个。它所做的是以图像为中心,但图像仍然缩小。 @LarsTech – taji01

+0

你能否提供一个链接到您在pageViewer.Image中使用的实际图片? – LarsTech

回答

1

您的图片已包含保证金,因此当您使用e.MarginBounds属性时,实际上可以使您的保证金翻倍。要修复,请改用PageBounds属性。

float widthFactor = newWidth/e.PageBounds.Width; 
float heightFactor = newHeight/e.PageBounds.Height; 
+0

再次感谢你LarsTech你真的很有帮助:) – taji01