Question Create large image from 5 different images

a_eliran

New member
Joined
May 30, 2009
Messages
1
Programming Experience
Beginner
Hi all i need help with project i've built with VB.Net
it's my first time handling with this code.

This project creates images with different sizes (5 images).
I handled very well with the images resize but now I need to create new large image that includes all the images i have saved before (5 images only).
They should be arranged side by side in any order, it doesn't matter how.
This is how the code looks like:

Dim Frame, W, H As Integer
Dim p As New PictureBox()
W = 133
H = 167
For Frame = 1 To 5
Dim bmp As New Bitmap(Form2.picImage1.Image, W, H)
Form2.Show()
bmp.Save(filename:="c:\" & Frame & ".bmp")
W = W - 10
H = H - 10
Next Frame
W = 10
H = 20
For Frame = 1 To 5
p.Image = Image.FromFile(filename:="c:\" & Frame & ".bmp")
p.Location = New Point(W, H)
p.Show()

W = W + 10
H = H + 10
Me.Controls.Add(p)
Next Frame
p.Image.Save(filename:="c:\Full.bmp")

it's very important and urgent
Any solutions? :\
 
VB.NET:
Dim img1 As Image
Dim img2 As Image
Dim img3 As Image
Dim img4 As Image
Dim img5 As Image

'...

Dim width As Integer = img1.Width + _
                       img2.Width + _
                       img3.Width + _
                       img4.Width + _
                       img5.Width
Dim height As Integer = Math.Max(img1.Height, _
                                 Math.Max(img2.Height, _
                                          Math.Max(img3.Height, _
                                                   Math.Max(img4.Height, _
                                                            img5.Height))))

Dim combinedImage As New Bitmap(width, height)
Dim x As Integer = 0

Using g As Graphics = Graphics.FromImage(combinedImage)
    g.DrawImage(img1, x, 0)
    x += img1.Width
    g.DrawImage(img2, x, 0)
    x += img2.Width
    g.DrawImage(img3, x, 0)
    x += img3.Width
    g.DrawImage(img4, x, 0)
    x += img4.Width
    g.DrawImage(img5, x, 0)
End Using
 
As you're using .NET 3.5 you might also get the height like so:
VB.NET:
Dim height As Integer = New Integer() {img1.Height, _
                                       img2.Height, _
                                       img3.Height, _
                                       img4.Height, _
                                       img5.Height}.Max()
 
Back
Top