Concatenating images into columns and rows


Dec 16, 2010
Programming Experience
For my example I have 256 individual image tiles, each 256px width X 256px height.
The goal is to concatenate these to a single image 4096px w X 4096px H. (256*16=4096)
The tile are named so the first 16 alphabetically make up the first column decending top to bottom, the second 16 make up the second column and so on. I googled for ideas but mostly found what I have so far here on this forum. For clarity I am attaching a txt file with the file name list that I am using.
This works for me but I was wondering if the is a more elegant or 'best practices approach' than what I am doing. While this is something that I will use regularly, I am using it to help learn

Imports System.Drawing.Imaging
Public Class Form1
Dim objTileList As New ArrayList
Dim CompositImage As New Bitmap(4096, 4096)
Dim g As Graphics = Graphics.FromImage(CompositImage)
Dim intX As Integer = 0
Dim intY As Integer = 0
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button2.Click
' the folder containing the .png images
' hardcoded for now
Dim dirInfo As New IO.DirectoryInfo _
' create an array of all of the file names
Dim aryFiles As IO.FileInfo() = dirInfo.GetFiles("*.png")
' populate an ArrayList with the file names
For Each file In aryFiles
' hardcoded for now
objTileList.Add("F:\VB_combine_images\AthensTexasDL_files\" & file.ToString)
' number of files to begin with
Dim intTotalNumberOfTiles As Integer = objTileList.Count
' number of columns & rows (-1 for zero based)
Dim intSqrRoot As Integer = Math.Sqrt(intTotalNumberOfTiles) - 1
For i = 0 To intSqrRoot ' increment by 256px for new column
For j = 0 To intSqrRoot ' build column rows by adding each new tile to bottom
Dim strTempFileName As String = objTileList.Item(0)
Dim Image1 As New Bitmap(strTempFileName)
g.DrawImage(Image1, New Point(intX, intY))
intY += 256 ' next tile is 256px lower
objTileList.RemoveAt(0) ' remove this tile from the ArrayList TileList
Next ' j
intY = 0
intX += 256 ' next column is 256px to the right
Next ' i
End Sub
End Class


  • fileList.txt
    8.6 KB · Views: 22
Top Bottom