Click here to Skip to main content
14,693,685 members
Articles » Multimedia » General Graphics » Image Display
Posted 22 Jan 2006


82 bookmarked

Merging Images in .NET

Rate me:
Please Sign up or sign in to vote.
3.96/5 (108 votes)
28 Jun 2006CPOL
Sometimes, we need to place one or more images on the other image’s surface or create an image from a few image files by joining them together. For example, we have “a.jpg”, “b.jpg” and “c.jpg” files and we need to create an image with the word “abc”. In this short tutorial, I will show how to do th
Sample Image - output.jpg


Sometimes, we need to place one or more images on the other image’s surface or create an image from a few image files by joining them together. For example, we have a.jpg, b.jpg and c.jpg files and we need to create an image with the word “abc”. In this short tutorial, I will show how to do this.

The System.Drawing namespace in the .NET Framework provides access to basic graphics functionality and System.Drawing.Imagine namespace includes classes and interfaces that provide imaging functionality. To use those namespaces, you need to add a reference to System.Drawing.dll in the Solution Explorer.


Now let’s discuss the code. At first, we need to create a new image on the surface of which we will place all three images (a, b, c) to create the word “abc”:

// Create a new image
Image img = new Bitmap(300, 100);

Two parameters determine the dimension of the new image. If we want to use the already existing image as background, we can create an image from file:

// Create image object from existing image
Image img = Image.FromFile("Image.jpg");

Before make changes with img, we need to convert it to a Graphics object:

Graphics g = Graphics.FromImage(img);

Now using Graphics.DrawImage method, we can put all letters on the image:

// Place a.gif
g.DrawImage(Image.FromFile("a.gif"), new Point(10, 10));
// Place b.jpg
g.DrawImage(Image.FromFile("b.jpg"), new Point(70, 10));
// Place c.jpg
g.DrawImage(Image.FromFile("c.jpg"), new Point(130, 10));

The first parameter is the image object, the second – object Point that we use to determine a position by rectangular coordinates.

To save the result in a file, call the Image.Save method:

// Save changes as output.jpg
img.Save("output.jpg", ImageFormat.Jpeg);

GDI library supports a lot of graphic formats. For instance, you can save the result as GIF or PNG:

// Save changes as output.gif
img.Save("output.gif", ImageFormat.Gif);

// Save changes as output.png
img.Save("output.png", ImageFormat.Png);

To display graphics without a white border, I saved letter A as a GIF file and used transparency. As we see far in the result, Graphics.DrawImage method detects that Image object includes a transparency layer and places it in the right way.

All source files with example images can be download from here.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Alexander Kleshchevnikov
Web Developer
Ukraine Ukraine
Alexander is freelance web developer with 4 years experience. He has skills in ASP.NET/MS SQL Server, PHP/MySQL, Ruby On Rails, XHTML, CSS. You can contact with me by Also check my homepage at

Comments and Discussions

PraiseThanks a lot for sharing Pin
MrNams1-Aug-18 23:00
MemberMrNams1-Aug-18 23:00 
Bugplease edit your instructions Pin
Member 136064734-Jan-18 0:10
MemberMember 136064734-Jan-18 0:10 
QuestionGOOD Pin
somnath chaturvedi3-Oct-17 0:36
Membersomnath chaturvedi3-Oct-17 0:36 
QuestionMerging Images in Silverlight Pin
buddenn9-Sep-16 5:58
Memberbuddenn9-Sep-16 5:58 
GeneralThanks it worked !!! Pin
VinayR@J3-Dec-13 0:30
professionalVinayR@J3-Dec-13 0:30 
QuestionMerging two image reduce the image size Pin
Anbu arunmozhi19-Jul-13 0:11
MemberAnbu arunmozhi19-Jul-13 0:11 
AnswerRe: Merging two image reduce the image size Pin
SaintKith21-Oct-14 21:33
MemberSaintKith21-Oct-14 21:33 
GeneralMy vote of 2 Pin
Anbu arunmozhi19-Jul-13 0:10
MemberAnbu arunmozhi19-Jul-13 0:10 
Questionsir is it possible to using drag ans drop to picturebox Pin
gunakar11-May-13 6:57
Membergunakar11-May-13 6:57 
QuestionHow did you enable the transparency layer for a.gif?? Pin
Rajiv Charan Tej K21-Oct-12 21:25
MemberRajiv Charan Tej K21-Oct-12 21:25 
AnswerRe: How did you enable the transparency layer for a.gif?? Pin
Anbu arunmozhi19-Jul-13 0:13
MemberAnbu arunmozhi19-Jul-13 0:13 
GeneralMy vote of 5 Pin
Ashish Tripathi13-Sep-12 7:40
MemberAshish Tripathi13-Sep-12 7:40 
Questionoverlay image on video Pin
jymitra13-Feb-11 20:40
Memberjymitra13-Feb-11 20:40 
GeneralMy vote of 5 Pin
Michael Boyd22-Sep-10 5:29
professionalMichael Boyd22-Sep-10 5:29 
GeneralForgot to vote Pin
Don Driskell22-Jul-09 5:53
MemberDon Driskell22-Jul-09 5:53 
GeneralNice Article Pin
Don Driskell22-Jul-09 5:48
MemberDon Driskell22-Jul-09 5:48 
GeneralRe: Nice Article Pin
fgimage19-Jun-13 21:16
Memberfgimage19-Jun-13 21:16 
GeneralRelease Memory Pin
JesseZ1-May-07 10:52
MemberJesseZ1-May-07 10:52 
GeneralUpdated June 29, 2006 Pin
firmwaredsp29-Jun-06 19:03
Memberfirmwaredsp29-Jun-06 19:03 
GeneralJust curious... Pin
Jun Du7-Jun-06 9:53
MemberJun Du7-Jun-06 9:53 
GeneralRe: Just curious... Pin
Alexander Kleshchevnikov7-Jun-06 11:49
MemberAlexander Kleshchevnikov7-Jun-06 11:49 
GeneralGood Pin
gbuela29-May-06 2:54
Membergbuela29-May-06 2:54 
GeneralRe: Good Pin
Stuart Roberts7-Jun-06 19:50
MemberStuart Roberts7-Jun-06 19:50 
GeneralRe: Good Pin
Robban198025-Mar-07 6:40
MemberRobban198025-Mar-07 6:40 
GeneralWhy Vote so low Pin
NormDroid23-Jan-06 5:08
professionalNormDroid23-Jan-06 5:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.