通過 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#,可以輕鬆合併不同的格式,包括。