我試圖使用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
你能張貼代碼做大小調整?這可能是你實際上裁剪圖像,而不是調整大小。 – briddums
根據['Bounds'文檔](http://msdn.microsoft.com/en-us/library/system.drawing.printing.pagesettings.bounds.aspx),我看到它說:「使用Bounds屬性以及邊距屬性來計算頁面的打印區域。「你是否應該減去'printSettings.DefaultPageSettings.Margins'中的值? – lsuarez
可能的問題是圖像大小調整代碼。只是不要調整它的大小,用Graphics.DrawImage(Image,Rectangle)重載繪製它。作爲獎勵,你會獲得更好的輸出質量。 –