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

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.
//your code here... // 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

Url: http://www.aspose.com/.net/imaging-component.aspx

Language: C# | User: Sheraz Khan | Created: May 18, 2016 | Tags: Combine multiple Images into Single Image Combine Images using Graphics Class Combine multiple Images Create an instance of Image creates new Image canvas in JPEG .NET image processing