将位图打印为A4尺寸,无需拉伸

问题描述 投票:0回答:1

enter image description here

Public Class Form1

    Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

        Dim margX As Single = e.PageSettings.HardMarginX
        Dim margY As Single = e.PageSettings.HardMarginY
        Dim adjustToA4 As New Rectangle(e.PageBounds.Left - margX, e.PageBounds.Top - margY, e.PageBounds.Width, e.PageBounds.Height)


        Dim dm As New Bitmap(Panel2.Width, Panel2.Height)
        Panel2.DrawToBitmap(dm, New Rectangle(0, 0, Panel2.Width, Panel2.Height))

        e.Graphics.DrawImage(dm, adjustToA4)

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.ShowDialog()

    End Sub

End Class

此编码允许位图打印为 A4 尺寸...但位图不是 A4 尺寸的原始形式。 那么,有什么编码可以将位图放大或缩小到A4尺寸而不影响位图的形状呢? 谢谢...

“翻译”....

将位图放大或缩小到 A4 大小而不拉伸....VB 2022

vb.net printing bitmap stretch
1个回答
0
投票
Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    PrintPreviewDialog1.Document = PrintDocument1
    PrintPreviewDialog1.ShowDialog()

    PrintPreviewDialog1.Document = PrintDocument2
    PrintPreviewDialog1.ShowDialog()

End Sub

Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

    Dim margX As Single = e.PageSettings.HardMarginX
    Dim margY As Single = e.PageSettings.HardMarginY
    Dim adjustToA4 As New Rectangle(e.PageBounds.Left - margX, e.PageBounds.Top - margY, e.PageBounds.Width, e.PageBounds.Height)

    Dim dm As New Bitmap(Panel2.Width, Panel2.Height)
    Panel2.DrawToBitmap(dm, New Rectangle(0, 0, Panel2.Width, Panel2.Height))

    e.Graphics.DrawImage(dm, adjustToA4)

End Sub

Private Sub PrintDocument2_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument2.PrintPage
    Dim adjustToA4 As New Rectangle(25, 30, e.PageBounds.Width - 60, e.PageBounds.Height - 50)

    Dim dm As New Bitmap(Panel1.Width, Panel1.Height)
    Panel1.DrawToBitmap(dm, New Rectangle(0, 0, Panel1.Width, Panel1.Height))

    e.Graphics.DrawImage(dm, adjustToA4)
End Sub

下课

© www.soinside.com 2019 - 2024. All rights reserved.