Hi Apeksha,
Refer below code.
Namespaces
C#
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.IO;
VB.Net
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Drawing.Text
Imports System.IO
Code
C#
protected void MergeThreeImages(object sender, EventArgs e)
{
Image img1 = Image.FromFile(Server.MapPath("~/QRCode/" + QRCodejJPG), true);
Image img2 = Image.FromFile(Server.MapPath("~/StringImage/" + StringJPG), true);
Image img3 = Image.FromFile(Server.MapPath("~/QRCodeFormet/NEWImage.png"), true);
List<Image> fileList = new List<Image>();
fileList.Add(img1);
fileList.Add(img2);
fileList.Add(img3);
Bitmap bitmap1 = MergeImages(fileList);
bitmap1.Save(Server.MapPath("~/FinalQRCode/") + StringJPG, ImageFormat.Jpeg);
}
public static Bitmap MergeImages(List<Image> images)
{
int outputImageWidth = 0;
int outputImageHeight = 1;
foreach (Image image in images)
{
outputImageHeight += image.Height;
if (image.Width > outputImageWidth)
{
outputImageWidth = image.Width;
}
}
Bitmap outputImage = new Bitmap(outputImageWidth, outputImageHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using (Graphics graphics = Graphics.FromImage(outputImage))
{
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.Clear(Color.White);
graphics.DrawImage(images[0], new Rectangle(new Point(), images[0].Size), new Rectangle(new Point(), images[0].Size), GraphicsUnit.Pixel);
graphics.DrawImage(images[1], new Rectangle(new Point(0, images[0].Height + 1), images[1].Size), new Rectangle(new Point(), images[1].Size), GraphicsUnit.Pixel);
graphics.DrawImage(images[2], new Rectangle(new Point(0, images[0].Height + images[1].Height + 1), images[2].Size), new Rectangle(new Point(), images[2].Size), GraphicsUnit.Pixel);
}
return outputImage;
}
VB.Net
Protected Sub MergeThreeImages(ByVal sender As Object, ByVal e As EventArgs)
Dim img1 As Image = Image.FromFile(Server.MapPath("~/QRCode/" & QRCodejJPG), True)
Dim img2 As Image = Image.FromFile(Server.MapPath("~/StringImage/" & StringJPG), True)
Dim img3 As Image = Image.FromFile(Server.MapPath("~/QRCodeFormet/NEWImage.png"), True)
Dim fileList As List(Of Image) = New List(Of Image)()
fileList.Add(img1)
fileList.Add(img2)
fileList.Add(img3)
Dim bitmap1 As Bitmap = MergeImages(fileList)
bitmap1.Save(Server.MapPath("~/FinalQRCode/") + StringJPG, ImageFormat.Jpeg)
End Sub
Public Shared Function MergeImages(ByVal images As List(Of Image)) As Bitmap
Dim outputImageWidth As Integer = 0
Dim outputImageHeight As Integer = 1
For Each image As Image In images
outputImageHeight += image.Height
If image.Width > outputImageWidth Then
outputImageWidth = image.Width
End If
Next
Dim outputImage As Bitmap = New Bitmap(outputImageWidth, outputImageHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Using graphics As Graphics = graphics.FromImage(outputImage)
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality
graphics.Clear(Color.White)
graphics.DrawImage(images(0), New Rectangle(New Point(), images(0).Size), New Rectangle(New Point(), images(0).Size), GraphicsUnit.Pixel)
graphics.DrawImage(images(1), New Rectangle(New Point(0, images(0).Height + 1), images(1).Size), New Rectangle(New Point(), images(1).Size), GraphicsUnit.Pixel)
graphics.DrawImage(images(2), New Rectangle(New Point(0, images(0).Height + images(1).Height + 1), images(2).Size), New Rectangle(New Point(), images(2).Size), GraphicsUnit.Pixel)
End Using
Return outputImage
End Function