Home > Code > C# > How to Combine Two or Multiple Images into a Single Image inside .NET Apps

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

by sher azam   on May 18, 2016   Category: C#   |  Views: 481    |  Points: 25   |  Gold 


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.

- Homepage of Aspose.Imaging for .NET: http://www.aspose.com/.net/imaging-component.aspx

- Download Aspose.Imaging for .NET: http://www.aspose.com/downloads/imaging-family/net



Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts