我正在尝试在 VB.NET 中以 A4 尺寸输出将合并多图像导出到一页两侧(2 x 5)。 所以总图像是 1 张 A4 页中的 10 张
请指导我
谢谢
Imports System.IO
Public Class Form1
Private PATH As String = Directory.GetCurrentDirectory()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim img1 As Image = Image.FromFile(PATH & "\ExportedBusinessCard0.png")
Dim img2 As Image = Image.FromFile(PATH & "\ExportedBusinessCard0.png")
Dim b As Bitmap = MergeImages(img1, img2, 10)
End Sub
Private Function MergeImages(ByVal image1 As Image, ByVal image2 As Image, ByVal space As Integer) As Bitmap
Dim bitmap As New Bitmap(image1.Width + image2.Width + space, Math.Max(image1.Height, image2.Height))
Using g As Graphics = Graphics.FromImage(bitmap)
g.Clear(Color.White)
g.DrawImage(image1, 0, 0)
g.DrawImage(image2, image1.Width + space, 0)
End Using
Dim img As Image = bitmap
img.Save(PATH & "\A4twoside.jpg")
Return bitmap
End Function
End Class
代码结果
示例图片
所需输出
需要按数字迭代图像;让我们称迭代器为
i
。 x 位置将为:
(i mod 2) * columnWidth + leftMargin
y 位置将为:
i \ 5 * rowHeight + topMargin
(反斜杠在 VB.NET 中执行整数除法。)
我建议使用铅笔和纸来研究如何添加填充。