1. 产品
  2.   Aspose.Imaging
  3.   图像合并

NET 的图像合并工具

通过无缝组合不同的图像,制作迷人的照片拼贴。

.NET图像合并插件

Aspose.Imaging 的 Image Merger for .NET 插件允许您在不损失质量的情况下垂直或水平合并图像,促进创造力,打造各种照片拼贴作品。这款多功能工具支持各种文件格式,为您提供灵活性,轻松创建引人入胜的视觉组合。

如何通过.NET合并图像?

  • 在您的项目中引用 Aspose.Imaging
  • 设置许可证密钥.
  • 将输入图像加载到收集参考数据。
  • 考虑输入参考数据和合并布局来创建输出图像
  • 为输出图像创建 Graphics
  • 使用选定的合并策略绘制输入图像
  • 可选地,在处理之前调整输入图像的大小

NET先决条件的图像合并工具

downloads 获取相应的组件文件,或从 NuGet 获取软件包,将 Aspose.Imaging 直接添加到您的工作区。

  • Microsoft Windows 或兼容的带有 .NET Core 的操作系统
  • 类似 Visual Studio Code 或 Microsoft Visual Studio 这样的开发环境


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 的图像合并器?

.NET 图像合并器使您能够轻松创建惊艳的拼贴,是设计师和摄影师的必备工具。它经过优化以提高性能,确保您可以毫不滞后地处理高分辨率图像,从而实现快速和高效的工作流程。

常见问题

照片拼貼是什麼?

照片拼貼是通過結合多張圖像來創建新的照片或圖像。這些圖像可能與彼此沒有直接關聯,從而可形成多樣且具有創意的構圖。

在创建照片拼贴时可以实现什么效果?

摄影师可以通过在一幅图像上叠加另一幅图像,或将许多图像合并成一个整体来实现照片拼贴中的所需效果。这个过程可以涉及超过两幅图像,并且结果可能包含对不同摄影图像的混乱使用,类似于拼图或马赛克。

Image Merger 插件支持哪些图片格式?

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 以获取工作示例和样本。

  

支持和学习资源

  
 中文