Combine Images in VB.NET

woklet

Active member
Joined
Mar 9, 2005
Messages
29
Im looking for source code in VB.NET on how to concatenate two bitmaps together, top and bottom.

Ive tried using the BitBlt function but cant quite seem to get it.

Thanks in advance,
Ben
 
Code:
        Dim Image1 As New Bitmap("c:\test.bmp")
        Dim Image2 As New Bitmap("c:\test.bmp")

        Dim Image3 As New Bitmap(600, 1000)
        Dim g As Graphics = Graphics.FromImage(Image3)
        g.DrawImage(Image1, New Point(0, 0))
        g.DrawImage(Image2, New Point(0, 500))
        g.Dispose()
        g = Nothing

        PictureBox1.Image = Image3

This will open a bitmap file that just happens to be 300x500 and load it into Image1 & Image2, image3 then Combines the two images into one big 600x1000 and displays it in a picturebox

Hope that helps

Andy
 
Depending on your needs, you might want to turn it into a function.

Code:
Function JoinImagesVert(Image1 As Bitmap, Image2 As Bitmap) As Bitmap
    Dim Result As New Bitmap(Math.Max(Image1.Width, Image2.Width), _
        Image1.Height + Image2.Height)
    Dim gResult As Graphics = Graphics.FromImage(Resi;t)
    gResult.DrawImage(Image1, New Point(0, 0))
    gResult.DrawImage(Image2, New Point(0, Image1.Height))
    gResult.Dispose()
    gResult = Nothing

    Return Result
 
Back
Top