2015-07-03 16 views
0

我有任何尺寸的圖像(例如100x100像素),我需要打印拉伸到固定尺寸A4(210 x 297毫米 - 毫米,不是像素..)如何在VB NET中將任意大小的圖片打印到完整的A4頁面?

如何打印任何尺寸的圖片在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 

回答

0

創建一個矩形和圖像繪製到與此重載爲DrawImage方法。根據需要更改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 
+0

確定,但「......新的Rectangle(...」 parametters是以像素爲單位。我需要設置的大小以毫米爲單位。像素圖像 大小並不重要,我需要建立大小毫米,並將圖像拉伸爲完整的A4尺寸。 – Martin

+0

您可以檢查頁面的寬度和高度,以像素爲單位,並相應地顯示矩形。 – OneFineDay

相關問題