by
8,582 17

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.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1235132/How-to-Combine-Two-or-Multiple-Images-in?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// Enter here the actual content of the snippet. // 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
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus