Aspose.Imaging 的 Image Merger for .NET 插件允许您在不损失质量的情况下垂直或水平合并图像,促进创造力,打造各种照片拼贴作品。这款多功能工具支持各种文件格式,为您提供灵活性,轻松创建引人入胜的视觉组合。
Graphics
类using 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); | |
} |
.NET 图像合并器使您能够轻松创建惊艳的拼贴,是设计师和摄影师的必备工具。它经过优化以提高性能,确保您可以毫不滞后地处理高分辨率图像,从而实现快速和高效的工作流程。
照片拼貼是通過結合多張圖像來創建新的照片或圖像。這些圖像可能與彼此沒有直接關聯,從而可形成多樣且具有創意的構圖。
摄影师可以通过在一幅图像上叠加另一幅图像,或将许多图像合并成一个整体来实现照片拼贴中的所需效果。这个过程可以涉及超过两幅图像,并且结果可能包含对不同摄影图像的混乱使用,类似于拼图或马赛克。
Aspose.Imaging 的 Image Merger for .NET 插件支持广泛的图像格式进行合并,包括 WebP、WMF、TIFF、PNG、SVG、ODG、OTG、JPG、JP2、ICO、J2K、EPS、GIF、DNG、EMF、DJVU、DIB、DICOM、CDR、CMX、APNG 和 BMP。
它使得两个或更多图像在垂直或水平方向无缝组合,而且不会损失任何质量。
肯定要查看 GitHub Repository 以获取工作示例和样本。