2014年4月25日 星期五

Resize image (picturebox) for printing

引用來源
--
 Dim ImgX As Integer
Dim ImgY As Integer
Dim PSizeX As Integer
Dim PSizeY As Integer
Dim ScaleX As Double
Dim ScaleY As Double
Dim RecX As Integer
Dim RecY As Integer
Dim ScaleM As Double


ImgX = Me.PictureBox1.Image.Height
ImgY = Me.PictureBox1.Image.Width
If Me.PrintDocument1.DefaultPageSettings.Landscape = False Then
           PSizeX = Me.PrintDocument1.DefaultPageSettings.PaperSize.Height
           PSizeY = Me.PrintDocument1.DefaultPageSettings.PaperSize.Width
Else
           PSizeX = Me.PrintDocument1.DefaultPageSettings.PaperSize.Width
           PSizeY = Me.PrintDocument1.DefaultPageSettings.PaperSize.Height
End If
 ScaleX = PSizeX / ImgX
 ScaleY = PSizeY / ImgY
If ScaleX < ScaleY Then
  ScaleM = ScaleX
Else
  ScaleM = ScaleY
End If
 RecY = ImgY * ScaleM
 RecX = ImgX * ScaleM
 e.Graphics.DrawImage(PictureBox1.Image, 0, 0, RecY, RecX)



If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
           PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
           PrintDocument1.Print()
End If

沒有留言:

張貼留言