article

How to Combine Two or Multiple Images into a Single Image inside .NET Apps

Email
Submitted on: 5/18/2016 8:06:15 AM
By: Sherazam  
Level: Intermediate
User Rating: Unrated
Compatibility: C#, VB.NET
Views: 3795
 
     This technical tip explains how .NET developers can combine single or multiple images inside their .NET applications. This example uses Graphics class and shows how to combine two or more images into a single complete image. To demonstrate the operation, the example creates a new Image canvas in JPEG format and draw images on the canvas surface using DrawImage method exposed by Graphics class. Using Graphics class two or more images can be combine in such a way that the resultant image will look as a complete image with no space between the image parts and no pages.

 
				This technical tip explains how .NET developers can combine single or multiple images inside their .NET applications. This example uses Graphics class and shows how to combine two or more images into a single complete image. To demonstrate the operation, the example creates a new Image canvas in JPEG format and draw images on the canvas surface using DrawImage method exposed by Graphics class. Using Graphics class two or more images can be combine in such a way that the resultant image will look as a complete image with no space between the image parts and no pages. Following is the code demonstration that shows how to use DrawImage method of the Graphics class to combine images in a single image.
// Combining Images using Graphics Class
//[C# Code Sample]
//Create an instance of JpegOptions and set its various properties
Aspose.Imaging.ImageOptions.JpegOptions ImageOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
//Create an instance of FileCreateSource and assign it to Source property
ImageOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(@"two_images_result.jpeg", false);
//Create an instance of Image and define canvas size
using (var image = Aspose.Imaging.Image.Create(ImageOptions, 600, 600))
{
 //Create and initialize an instance of Graphics
 var graphics = new Aspose.Imaging.Graphics(image);
 //Clear the image surface with white color
 graphics.Clear(Aspose.Imaging.Color.White);
 // Draw Image
 graphics.DrawImage(Aspose.Imaging.Image.Load(@"input1.jpg"), 0, 0, 600, 300);
 graphics.DrawImage(Aspose.Imaging.Image.Load(@"input2.jpg"), 0, 300, 600, 300);
 // Call save method to save the resultant image.
 image.Save();
}
 
//[VB.NET Code Sample]
'Create an instance of JpegOptions and set its various properties
Dim ImageOptions As New Aspose.Imaging.ImageOptions.JpegOptions()
'Create an instance of FileCreateSource and assign it to Source property
ImageOptions.Source = New Aspose.Imaging.Sources.FileCreateSource("two_images_result.jpeg", False)
'Create an instance of Image and define canvas size
Using image = Aspose.Imaging.Image.Create(ImageOptions, 600, 600)
	'Create and initialize an instance of Graphics
	Dim graphics = New Aspose.Imaging.Graphics(image)
	'Clear the image surface with white color
	graphics.Clear(Aspose.Imaging.Color.White)
	' Draw Image
	graphics.DrawImage(Aspose.Imaging.Image.Load("input1.jpg"), 0, 0, 600, 300)
	graphics.DrawImage(Aspose.Imaging.Image.Load("input2.jpg"), 0, 300, 600, 300)
	' Call save method to save the resultant image.
	image.Save()
End Using
Overview: Aspose.Imaging for .NET
Aspose.Imaging for .NET is an image processing & manipulation component that allows developers to create, edit, draw or convert images in their .NET application. It allows developers to convert image files to PSD, BMP, JPEG, PNG, TIFF and GIF formats. Moreover a set of pens, brushes and fonts can be used to draw images or add new elements & text to existing images. Aspose.Imaging for .NET works well with both web & windows applications. Moreover, it adds the support for Silverlight platform.
 


Other 44 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.