Aspose.Imaging’s Image Merger for .NET plugin allows you to merge images vertically or horizontally without quality loss, fostering creativity in crafting diverse photo collages. This versatile tool supports various file formats, giving you the flexibility to effortlessly create captivating visual compositions.
Graphics
class for output imageusing Aspose.Imaging; | |
using Aspose.Imaging.FileFormats.Png; | |
using Aspose.Imaging.ImageOptions; | |
using Aspose.Imaging.Sources; | |
using System.Collections.Generic; | |
using System.IO; | |
string templatesFolder = @"c:\Users\USER\Downloads\templates\"; | |
string dataDir = templatesFolder; | |
var images = new List<Image>(); | |
string[] files = new string[] { "template.png", "template.jpg" }; | |
//Indicate how to merge, 0 - horizontal, 1 - vertical | |
byte[] mergeDirection = new byte[] { 0, 1 }; | |
int maxWidth = 0; | |
int maxHeight = 0; | |
int totalWidth = 0; | |
int totalHeight = 0; | |
foreach (var fileName in files) | |
{ | |
var image = Image.Load(dataDir + fileName); | |
totalWidth += image.Width; | |
if (image.Width > maxWidth) | |
{ | |
maxWidth = image.Width; | |
} | |
totalHeight += image.Height; | |
if (image.Height > maxHeight) | |
{ | |
maxHeight = image.Height; | |
} | |
images.Add(image); | |
} | |
MergeImages(0); | |
MergeImages(1); | |
images.ForEach(image => image.Dispose()); | |
File.Delete(dataDir + "result.gif"); | |
void MergeImages(byte direction) | |
{ | |
int targetWidth, targetHeight; | |
if (direction == 0) | |
{ | |
targetWidth = totalWidth; | |
targetHeight = maxHeight; | |
} | |
else | |
{ | |
targetWidth = maxWidth; | |
targetHeight = totalHeight; | |
} | |
var outputPath = dataDir; | |
outputPath = Path.Combine(outputPath, "result" + direction + ".png"); | |
var pngOptions = new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }; | |
using (Stream stream = new MemoryStream()) | |
{ | |
pngOptions.Source = new StreamSource(stream); | |
using (var image = Image.Create(pngOptions, targetWidth, targetHeight)) | |
{ | |
image.BackgroundColor = Color.White; | |
var graphics = new Graphics(image); | |
float x = 0, y = 0; | |
images.ForEach(image => | |
{ | |
graphics.DrawImage(image, new RectangleF(x, y, image.Width, image.Height)); | |
if (direction == 0) | |
{ | |
x += image.Width; | |
} | |
if (direction == 1) | |
{ | |
y += image.Height; | |
} | |
}); | |
image.Save(outputPath); | |
} | |
} | |
File.Delete(outputPath); | |
} |
The Image Merger for .NET allows you to create stunning collages effortlessly, making it an essential tool for designers and photographers. It is optimized for performance, ensuring that you can handle high-resolution images without lag, enabling quick and productive workflows.
A photo collage is the creation of a new photo or image by combining several images. These images may not be directly related to each other, allowing for diverse and creative compositions.
Photographers can achieve desired effects in a photo collage by superimposing one image on another or by combining many images into a single whole. This process can involve more than two images, and the result may include a chaotic use of different photographic images, resembling a puzzle or mosaic.
Aspose.Imaging’s Image Merger for .NET plugin supports a wide range of image formats for merging, including WEBP, WMF, TIFF, PNG, SVG, ODG, OTG, JPG, JP2, ICO, J2K, EPS, GIF, DNG, EMF, DJVU, DIB, DICOM, CDR, CMX, APNG, and BMP.
It enables the seamless combination of two or more images either vertically or horizontally without any loss in quality.
Definitely, check out the GitHub Repository for working examples & samples.