This can be done using the
Graphics
class in the
System.Drawing
namespace. First, you have load the two images you want to merge. Then, you create a new empty
Bitmap
where the width is the sum of the two widths of the loaded images, and the height is the maximum height of those images. After doing that, create a
Graphics
from that Bitmap and use the
DrawImage
method to draw the image on the graphics. At the end, the new
Bitmap
will contain a merged image, which you'll need to save. The code also contains a few
Dispose()
calls, which releases all used resources by those objects. Note: don't dispose an object if you need it later.
Image img1 = Image.FromFile("part1.png");
Image img2 = Image.FromFile("part2.png");
int newHeight = Math.Max(img1.Height, img2.Height);
int newWidth = img1.Width + img2.Width;
Bitmap merged = new Bitmap(newWidth, newHeight);
Graphics gr = Graphics.FromImage(merged);
gr.DrawImage(img1, new Point(0, 0));
gr.DrawImage(img2, new Point(img1.Width, 0));
gr.Dispose();
merged.Save("result.png", ImageFormat.Png);
img1.Dispose();
img2.Dispose();
merged.Dispose();