2016-03-04 127 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