我使用下面的代碼從PictureBox打印圖像。 所有的作品都很棒,除了縮小圖像大小比打印頁面大。 有沒有一種方法我錯過了這樣做?縮放打印圖像
截圖,紙張邊界外大的圖像:
http://a.yfrog.com/img46/63/problemsh.png http://a.yfrog.com/img46/63/problemsh.png
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AddHandler PrintDocument1.PrintPage, AddressOf OnPrintPage
With PageSetupDialog1
.Document = PrintDocument1
.PageSettings = PrintDocument1.DefaultPageSettings
If PictureEdit1.Image.Height >= PictureEdit1.Image.Width Then
PageSetupDialog1.PageSettings.Landscape = False
Else
PageSetupDialog1.PageSettings.Landscape = True
End If
End With
PrintDialog1.UseEXDialog = True
PrintDialog1.Document = PrintDocument1
If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PrintPreviewDialog1.Document = PrintDocument1
If PrintPreviewDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
PrintDocument1.Print()
End If
End If
End Sub
Private Sub OnPrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim img As Image = PictureEdit1.Image
Dim sz As New SizeF(100 * img.Width/img.HorizontalResolution, 100 * img.Height/img.VerticalResolution)
Dim p As New PointF((e.PageBounds.Width - sz.Width)/2, (e.PageBounds.Height - sz.Height)/2)
e.Graphics.DrawImage(img, p)
End Sub
的偉大工程,使培訓就業處是 - Scalefac :) – madlan 2010-08-19 20:26:14