Blog Home  Home Feed your aggregator (RSS 2.0)  
Software Code Help - How to Merge two images in ASP.NET 2.0 using C#
Blog
 
# Wednesday, July 08, 2009
//Create Two image Server path    
string strImagePath1 = Server.MapPath("Image1.jpg");
string strImagePath2 = Server.MapPath("Image2.jpg");
//Get Image objct
System.Drawing.Image FirstImage = Bitmap.FromFile(strImagePath1);
Graphics objGraphics = Graphics.FromImage(FirstImage);
System.Drawing.Image SecondImage = Bitmap.FromFile(strImagePath2);

int iFirstImageWidth, iFirstImageHeight, iSecondImageWidth, iSecondImageHeight;
int xPos, yPos;
//Retrieve the Height and Width of Images
iFirstImageWidth = FirstImage.Width;
iFirstImageHeight= FirstImage.Height;
iSecondImageWidth = SecondImage.Width;
iSecondImageHeight = SecondImage.Height;
//Retrieving the position where to image merge    
xPos = (iFirstImageWidth - iSecondImageWidth) / 2;
yPos = (iFirstImageHeight - iSecondImageHeight) / 2;
//Draw Second Image into First Image
objGraphics.DrawImage(SecondImage, new Point(xPos, yPos));

Response.ContentType = "image/JPEG";
//Save the Merge Image
FirstImage.Save(Server.MapPath("MergeImage.jpg"), ImageFormat.Jpeg);
Wednesday, July 08, 2009 6:43:01 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   C#  | 
Copyright © 2010 SoftwareCodeHelp. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: