2011-09-26 44 views
2

我試圖使用PrintDocument將圖像(從文件)打印到打印機。問題調整圖像以適合打印頁面

我正在重新調整圖像大小,以便在打印時將其縮放爲打印輸出的整頁,從而使圖像稍微裁剪。

EDIT 2

上午使用利潤來計算使用面積:

With printSettings.DefaultPageSettings 
    Dim areaWidth As Single = .Bounds.Width - .Margins.Left - .Margins.Right 
    Dim areaHeight As Single = .Bounds.Height - .Margins.Top - .Margins.Bottom 
End With 

頁的邊界是1169x827(A4),並與利潤率是1137x795 。

調整圖片的大小尺寸後是1092x682,我使用下面的代碼繪製: e.Graphics.DrawImage(printBitmap, .Margins.Left, .Margins.Top)

惱人的是,當我打印到PrintPreviewDialog上被完美地縮放,但是當我打印完全相同的代碼到它不適合的實際打印機。

編輯3

的完整代碼可以在this url 用法中找到:

Dim clsPrint As New clsPrinting 
    With clsPrint 
     .Landscape = True 
     .SetMinimumMargins() 
     If .ShowPrintDialog Then 
      .Documentname = "Some doc name" 
      .Preview = False 'When True shows ok 
      .PrintImage("filename of a png file") 
     End If 
    End With 
+0

你能張貼代碼做大小調整?這可能是你實際上裁剪圖像,而不是調整大小。 – briddums

+0

根據['Bounds'文檔](http://msdn.microsoft.com/en-us/library/system.drawing.printing.pagesettings.bounds.aspx),我看到它說:「使用Bounds屬性以及邊距屬性來計算頁面的打印區域。「你是否應該減去'printSettings.DefaultPageSettings.Margins'中的值? – lsuarez

+0

可能的問題是圖像大小調整代碼。只是不要調整它的大小,用Graphics.DrawImage(Image,Rectangle)重載繪製它。作爲獎勵,你會獲得更好的輸出質量。 –

回答

0

我沒有找到解決這個問題的方法。在執行打印預覽時忽略邊距(從0,0原點開始),我在打印時使用打印邊距來解決這個問題。我相信這可能是打印機驅動程序中的一個錯誤?但我無法證實。

0

聽起來像你想打印一個網頁,一個full bleed大多數個人打印機是不能夠的。正如上面的評論之一所提到的那樣,將邊緣因素重新調整爲合適的尺寸。

+0

實際上我想在邊距內打印它 - 請參閱EDIT2到我的原始文章 –

1

嘗試在PrintPage函數中使用e.graphics.VisibleClipBounds作爲可打印頁面大小。正如漢斯所說,最好不要在打印前調整圖像大小。

+0

e.Graphics.VisibleClipBounds包含與PrintableArea相同的寬度和高度,但原點爲0,0而不是「邊距」。左','邊緣。頂部' –

1

您必須MargiBounds工作:

C#

e.Graphics.DrawImage(your_image, e.MarginBounds); 

C++/CLI

e->Graphics->DrawImage(your_image, e->MarginBounds); 

注意:如果你的圖像不具有相同的縱橫比,你會需要調整。在圖像的這個例子寬度超出頁面寬度:

Dim adjustment As Double = img.Width/e.MarginBounds.Width 
e.Graphics.DrawImage(img, New Rectangle(New Point(0, 0), New Point(img.Width/adjustment, img.Height/adjustment)))