通过 C# 转到 JP2
构建您自己的 .NET 应用程序以使用服务器端 API 合并 JP2 文件。
如何使用 C# 合并 JP2 文件
如果您想让您的创造力尽情发挥,那么现在就是使用图像拼贴的时候了。即使源文件格式不同,此功能也允许您合并照片和图像。吸引人们注意您的作品集的一个好方法是使用带有重复图像或图案的照片壁纸。在这种情况下,可以在水平和垂直方向上组合图像。如果您需要演示处理文件的结果,您可以轻松合并两个图像:应用照片效果之前和之后。为了合并 JP2 文件,我们将使用 Aspose.Imaging for .NET API 是一个功能丰富、功能强大 易于使用的 C# 平台图像处理和转换 API。打开 NuGet 包管理器,搜索 Aspose.Imaging 并安装。您还可以从包管理器控制台使用以下命令。
包管理器控制台命令
PM> Install-Package Aspose.Imaging
通过 C# 合并 JP2 的步骤
你需要 aspose.imaging.dll 在您自己的环境中尝试以下工作流程。
- 使用 Image.Load 方法加载 JP2 文件
- 将图像组合成新图像
- 以 Aspose.Imaging 支持的格式将合并后的图像保存到光盘
系统要求
所有主要操作系统都支持 .NET 的 Aspose.Imaging。只需确保您具有以下先决条件。
- Microsoft Windows 或具有 .NET Framework、.NET Core、Windows 应用程序、ASP.NET Web 应用程序的兼容操作系统。
- Microsoft Visual Studio 等开发环境。
- 项目中引用的 Aspose.Imaging for .NET。
合并 JP2 图像 - .NET
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 API 的 Aspose.Imaging
Aspose.Imaging API 是一种图像处理解决方案,用于在应用程序中创建、修改、绘制或转换图像(照片)。它提供:跨平台的图像处理,包括但不限于各种图像格式之间的转换(包括统一的多页或多帧图像处理)、绘图等修改、使用图形基元、转换(调整大小、裁剪、翻转和旋转) 、二值化、灰度、调整)、高级图像处理功能(过滤、抖动、遮罩、去偏斜)和内存优化策略。它是一个独立的库,不依赖任何软件进行图像操作。可以在项目中使用原生 API 轻松添加高性能图像转换功能。这些是 100% 私有的本地 API,图像在您的服务器上处理。通过在线应用合并 JP2
通过访问我们的 Live Demos 网站 合并 JP2 文档。 现场演示有以下好处
JP2 什么是 JP2 文件格式
JPEG 2000 (JP2) 是一种图像编码系统和最先进的图像压缩标准。设计,使用小波技术 JPEG 2000 可以一次编码任何质量的无损内容。此外,在编码效率没有任何实质性损失的情况下,JPEG 2000 能够有效地访问相同的内容并将其解码为各种其他分辨率和质量。 JPEG 2000 中的码流具有显着的可扩展性,具有为空间随机访问提供便利的感兴趣区域。拥有多达 16384 个不同的组件,尺寸以万亿像素为单位,精度可高达 38 位/样本。
阅读更多其他支持的合并格式
使用 C#,可以轻松合并不同的格式,包括。