Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleCompose four pictures into a single picture and save the result into a file in Visual Basic .NET
DescriptionThis example shows how to compose four pictures into a single picture and save the result into a file in Visual Basic .NET
KeywordsTextBox, convert, proper case, StrConv, VB.NET
CategoriesGraphics, Controls, VB.NET
 
When the program starts, it loads the four pictures and makes a bitmap large enough to hold them. The program makes a Graphics object associated with this new bitmap and uses its DrawImage method to draw the four pictures onto it.

The program displays the result in a PictureBox and uses the result Bitmap's Save method to save the result into a file.

 
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
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated