如何在VB NET中将任意大小的图片打印到完整的A4页面?

时间:2015-07-03 14:27:37

标签: vb.net

我有任何尺寸的图像(例如100x100像素),我需要打印拉伸到固定尺寸A4(210 x 297 MM - mm,而不是像素..)

如何在VB NET中将任意大小的图片打印到完整的A4页面?

示例代码:

  Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    Dim newMargins As System.Drawing.Printing.Margins
    newMargins = New System.Drawing.Printing.Margins(0, 0, 0, 0)
    PrintDocument1.DefaultPageSettings.Margins = newMargins

    e.Graphics.DrawImage(picSource.Image, 0, 0)
End Sub


Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    PrintDocument1.Print()
End Sub

1 个答案:

答案 0 :(得分:0)

创建一个Rectangle,并使用DrawImage方法的Overload将图像绘制为该图像。根据需要更改x,y和大小。

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
 Dim newMargins As System.Drawing.Printing.Margins
 newMargins = New System.Drawing.Printing.Margins(0, 0, 0, 0)
 PrintDocument1.DefaultPageSettings.Margins = newMargins
 Dim ImgRect As New Rectangle(0,0,100,100)
 e.Graphics.DrawImage(picSource.Image, ImgRect)
End Sub