通過 C# 轉到 DNG
構建您自己的 .NET 應用程序以使用服務器端 API 合併 DNG 文件。
如何使用 C# 合併 DNG 文件
如果您想讓您的創造力盡情發揮,那麼現在就是使用圖像拼貼的時候了。即使源文件格式不同,此功能也允許您合併照片和圖像。吸引人們注意您的作品集的一個好方法是使用帶有重複圖像或圖案的照片壁紙。在這種情況下,可以在水平和垂直方向上組合圖像。如果您需要演示處理文件的結果,您可以輕鬆合併兩個圖像:應用照片效果之前和之後。為了合併 DNG 文件,我們將使用 Aspose.Imaging for .NET API 是一個功能豐富、功能強大且易於使用的 C# 平台圖像處理和轉換 API。打開 NuGet 包管理器,搜索 Aspose.Imaging 並安裝。您也可以從包管理器控制台使用以下命令。
包管理器控制台命令
PM> Install-Package Aspose.Imaging
通過 C# 合併 DNG 的步驟
你需要 aspose.imaging.dll 在您自己的環境中嘗試以下工作流程。
- 使用 Image.Load 方法加載 DNG 文件
- 將圖像組合成新圖像
- 以 Aspose.Imaging 支持的格式將合併後的圖像保存到光盤
系統要求
所有主要操作系統都支持 .NET 的 Aspose.Imaging。只需確保您具有以下先決條件。
- Microsoft Windows 或與 .NET Framework、.NET Core、Windows 應用程序、ASP.NET Web 應用程序兼容的操作系統。
- Microsoft Visual Studio 等開發環境。
- Aspose.Imaging for .NET 在您的項目中引用。
合併 DNG 圖像 - .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,圖像在您的服務器上處理。通過在線應用合併 DNG
通過訪問我們的 Live Demos 網站 合併 DNG 文檔。 現場演示有以下好處
DNG 什麼是 DNG 文件格式
DNG 是一種用於存儲原始文件的數碼相機圖像格式。它是由 Adobe 於 2004 年 9 月開發的。它基本上是為數碼攝影而開發的。 DNG 是 TIFF/EP 標準格式的擴展,大量使用元數據。為了輕鬆靈活地處理來自數碼相機的原始數據和藝術控制,攝影師選擇相機原始文件。 JPEG 和 TIFF 格式存儲由相機處理的圖像,因此在這些格式中沒有太大的更改空間。
閱讀更多其他支持的合併格式
使用 C#,可以輕鬆合併不同的格式,包括。