using Aspose.Imaging; using Aspose.Imaging.FileFormats.Jpeg; using Aspose.Imaging.FileFormats.Tiff; using Aspose.Imaging.FileFormats.Tiff.Enums; using Aspose.Imaging.ImageOptions; using Aspose.Imaging.Sources; using Aspose.Imaging.Xmp; using Aspose.Imaging.Xmp.Schemas.DublinCore; using Aspose.Imaging.Xmp.Schemas.Photoshop; using System; using System.Collections.Generic; using System.IO; using System.Linq; string templatesFolder = @"c:\Users\USER\Downloads\templates\"; string dataDir = templatesFolder; string[] imagePaths = { dataDir + "template.jpg", dataDir + "template.jpeg" }; string outputPath = dataDir + "result.png"; string tempFilePath = dataDir + "temp.jpg"; // Getting resulting image size. List<Size> imageSizes = new List<Size>(); foreach (string imagePath in imagePaths) { using (RasterImage image = (RasterImage)Image.Load(imagePath)) { imageSizes.Add(image.Size); } } int newWidth = imageSizes.Max(size => size.Width); int newHeight = imageSizes.Sum(size => size.Height); // Combining images into new one. using (MemoryStream memoryStream = new MemoryStream()) { StreamSource outputStreamSource = new StreamSource(memoryStream); JpegOptions options = new JpegOptions() { Source = outputStreamSource, Quality = 100 }; using (JpegImage newImage = (JpegImage)Image.Create(options, newWidth, newHeight)) { int stitchedHeight = 0; foreach (string imagePath in imagePaths) { using (RasterImage image = (RasterImage)Image.Load(imagePath)) { Rectangle bounds = new Rectangle(0, stitchedHeight, image.Width, image.Height); newImage.SaveArgb32Pixels(bounds, image.LoadArgb32Pixels(image.Bounds)); stitchedHeight += image.Height; } } newImage.Save(outputPath + ".png", new PngOptions()); } } File.Delete(outputPath);