In my TeboCam open source application I do this by stitching a list of bitmaps into one image.
Below is the method that does this:
public static Bitmap getMosaicBitmap(int imagesPerRow)
{
try
{
List<bitmap> imageItems = bitmaps;
int imgCount = imageItems.Count;
int imagesX;
int xCount = 1;
int xPos = 0;
int yPos = 0;
if (imgCount < imagesPerRow)
{
imagesX = imgCount;
}
else
{
imagesX = imagesPerRow;
}
int width = imageItems[0].Width;
int height = imageItems[0].Height;
int rows = (int)Math.Floor((decimal)imgCount / (decimal)imagesX);
bool remainder = decimal.Remainder((decimal)imgCount, (decimal)imagesX) > 0m;
if (remainder) rows++;
Bitmap mosaicImage = new System.Drawing.Bitmap(imagesX * width, rows * height);
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(mosaicImage))
{
g.Clear(System.Drawing.Color.Black);
for (int i = 0; i < imgCount; i++)
{
g.DrawImage(imageItems[i], new System.Drawing.Rectangle(xPos, yPos, imageItems[i].Width, imageItems[i].Height));
xCount++;
if (xCount > imagesX)
{
xPos = 0;
xCount = 1;
yPos = yPos + height;
}
else
{
xPos = xPos + width;
}
}
imageItems.Clear();
return mosaicImage;
}
}
catch
{
return null;
}
}
</bitmap>