How to merge images in one image
This code is help you to merge images into one image means combination of images but one this we have to remind that in images folder we have to remove Thumbs.db because if Thumbs.db is exist then this code will throw exception so we have to remove Thumbs.db.
First of create a function named Combine. this function merge images. You can put This code on page load also but i calling this function on button click event.
public static Bitmap Combine(string[] files)
{
//read all images into memory
List
Bitmap finalImage = null;
try
{
int width = 0;
int height = 0;
foreach (string image in files)
{
//create a Bitmap from the file and add it to the list
Bitmap bitmap = new Bitmap(image);
//update the size of the final bitmap
width += bitmap.Width;
height = bitmap.Height > height ? bitmap.Height : height;
images.Add(bitmap);
}
//create a bitmap to hold the combined image
finalImage = new Bitmap(width, height);
//get a graphics object from the image so we can draw on it
using (Graphics g = Graphics.FromImage(finalImage))
{
//set background color
g.Clear(Color.Black);
//go through each image and draw it on the final image
int offset = 0;
foreach (Bitmap image in images)
{
g.DrawImage(image,
new Rectangle(offset, 0, image.Width, image.Height));
offset += image.Width;
}
}
return finalImage;
}
catch (Exception)
{
if (finalImage != null)
finalImage.Dispose();
throw;
}
finally
{
//clean up memory
foreach (Bitmap image in images)
{
image.Dispose();
}
}
}
And then calling this function on button click event like this
protected void BtnMerge_Click(object sender, EventArgs e)
{
string[] Imagefiles = Directory.GetFiles(Server.MapPath("images"));
Bitmap stitchedImage = Combine(Imagefiles);
stitchedImage.Save(@"D:\Trial_Testing\Images\stitchedImage.jpg", ImageFormat.Jpeg);
}
In above code means button click event
string[] Imagefiles = Directory.GetFiles(Server.MapPath("images"));
In this code i give the path of the images
And
Bitmap stitchedImage = Combine(Imagefiles);
In this code i calling the function of Combine and give file array means file's path array. And finally
stitchedImage.Save(@"D:\Trial_Testing\Images\stitchedImage.jpg", ImageFormat.Jpeg);
In this code i saving image which is merged into one image on my local drive and spesific folder
And in function
List
Bitmap finalImage = null;
First create object of list(Bitmap) and Bitmap
And Then
int width = 0;
int height = 0;
foreach (string image in files)
{
//create a Bitmap from the file and add it to the list
Bitmap bitmap = new Bitmap(image);
//update the size of the final bitmap
width += bitmap.Width;
height = bitmap.Height > height ? bitmap.Height : height;
images.Add(bitmap);
}
This code count the number of images and add to a single bitmap. and yes here you can give the spesific height and width of the final image means merged image.
And
//create a bitmap to hold the combined image
finalImage = new Bitmap(width, height);
//get a graphics object from the image so we can draw on it
using (Graphics g = Graphics.FromImage(finalImage))
{
//set background color
g.Clear(Color.Black);
//go through each image and draw it on the final image
int offset = 0;
foreach (Bitmap image in images)
{
g.DrawImage(image,
new Rectangle(offset, 0, image.Width, image.Height));
offset += image.Width;
}
}
return finalImage;
}
catch (Exception)
{
if (finalImage != null)
finalImage.Dispose();
throw;
}
finally
{
//clean up memory
foreach (Bitmap image in images)
{
image.Dispose();
}
}
This code shows hold the images and draw the image with merging of all images and return the final image which is merged.
Imp Note:- Don't forget to remove Thumbs.Db from source folder

use image merger software or online image merger
See links
http://www.imagemerger.net/
http://www.pagecolumn.com/tool/imagemerger.htm
Regards
__________________________________-
Muhammad Farooq
http://fonts-guru.blogspot.com/