| 
                  | Title | Compose four pictures into a single picture and save the result into a file in Visual Basic .NET | 
|---|
 | Description | This example shows how to compose four pictures into a single picture and save the result into a file in Visual Basic .NET | 
|---|
 | Keywords | TextBox, convert, proper case, StrConv, VB.NET | 
|---|
 | Categories | Graphics, Controls, VB.NET | 
|---|
 | 
              
              
                | Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    ' Load the four pictures.
    Dim file_path As String = Application.StartupPath
    file_path = file_path.Substring(0, _
        file_path.LastIndexOf("\") + 1)
    Dim pic_names() As String = {"vb_prog_refs.jpg", _
        "offices.jpg", "ccls.jpg", "vbgps.jpg"}
    Dim bm(3) As Bitmap
    For i As Integer = 0 To 3
        bm(i) = New Bitmap(file_path & pic_names(i))
    Next i
    ' Make the result bitmap.
    Dim wid As Integer = Math.Max(bm(0).Width + _
        bm(1).Width, bm(2).Width + bm(3).Width)
    Dim hgt As Integer = Math.Max(bm(0).Height + _
        bm(2).Height, bm(1).Height + bm(3).Height)
    Dim bm_result As New Bitmap(wid, hgt)
    Dim gr As Graphics = Graphics.FromImage(bm_result)
    gr.DrawImage(bm(0), 0, 0, bm(0).Width, bm(0).Height)
    gr.DrawImage(bm(1), bm(0).Width, 0, bm(1).Width, _
        bm(1).Height)
    gr.DrawImage(bm(2), 0, bm(0).Height, bm(2).Width, _
        bm(2).Height)
    gr.DrawImage(bm(3), bm(2).Width, bm(1).Height, _
        bm(3).Width, bm(3).Height)
    gr.Dispose()
    ' Display the result.
    picResult.Image = bm_result
    ' Save into a file.
    bm_result.Save(file_path & "4pics.jpg", _
        ImageFormat.Jpeg)
    ' Clean up.
    For i As Integer = 0 To 3
        bm(i).Dispose()
    Next i
End Sub |