Merging Images

samsmithnz

Well-known member
Joined
Jul 22, 2003
Messages
1,038
Location
Boston
I have two bitmaps/gifs/jpgs/images that Id like to merge together. The two images are currently 20X20 pixels and Id like to create a final image with the two images side-by-side, so that the final image is 20X40 pixels.

Anyone have ANY idea how to do this in .Net?
 
I dont have the code here but what you can easily do is:
Create a new image, sized 20x40, and draw the original 2 images on top of it, one with an offset. I got some code that does something like this (it uses 5x5 bitmaps to fill a 50x100 or larger bitmap) but it is at home. Ill post it later today.
 
Damn, there goes my helpfulness!

I was going to suggest doing it the way Wile recommends, but i know its the coding not the method that your stuck on. That bit i couldnt really help you on.
 
You might give this function a try:

Code:
Private Function CombineBitmaps(ByVal bmp1 As Bitmap, ByVal bmp2 As Bitmap) As Bitmap
        find combined bitmaps new dimensions
        Dim bmpWidth As Integer = bmp1.Width + bmp2.Width
        Dim bmpHeight As Integer

        If bmp1.Height >= bmp2.Height Then
            bmpHeight = bmp1.Height
        Else : bmpHeight = bmp2.Height
        End If

        create a new bitmap for combining bmp1 and bmp2
        Dim bmp As Bitmap = New Bitmap(bmpWidth, bmpHeight)

        create the graphic object to draw the new bitmap
        Dim g As Graphics = Graphics.FromImage(bmp)

        draw bmp1 in the 0, 0 location
        g.DrawImage(bmp1, 0, 0)

        draw bmp2 next to bmp1
        g.DrawImage(bmp2, bmp1.Width, 0)

        dispose of graphic objects
        g.Dispose()

        and its done
        Return bmp

End Function

You could also add some scaling to the bitmaps if they are of different heights.
 
Last edited by a moderator:
Back
Top