Aspose.Imaging?for .NET是一款深受 .NET 開發人員喜愛的圖像處理 SDK,因為它靈活且易于開發人員使用。EMF 圖像文件格式提供出色的打印質量和可擴展性。此外,這種圖像文件格式還節省存儲空間。Aspose.Imaging for .NET??能夠使 SVG 到 EMF 的轉換變得簡單且經濟實惠。本教程將演示如何借助Aspose.Imaging?for .NET在 C# 中無縫地將SVG轉換為EMF。請確保您已在計算機上安裝 .NET,以便可以立即實現該功能。
Aspose.Imaging for .NET官方正版下載
圖像處理 SDK - 安裝
我們將安裝Aspose.Imaging for .NET。請訪問此鏈接下載。
Install-Package Aspose.Imaging
使用 C# 編程將 SVG 轉換為 EMF
您可以按照以下步驟開發 SVG 到 EMF 轉換器:
- 循環遍歷文件數組。
- 通過調用Image.Load(inputFileName)方法加載源 SVG 文件。
- 將 SVG光柵化選項設置為與原始圖像相同的頁面大小。
- 初始化 EMF選項并分配 SVG 光柵化設置以進行矢量渲染。
- Save方法將把生成的 EMF 文件保存到磁盤上。
以下代碼示例展示了如何以編程方式在 C# 中將 SVG 轉換為 EMF:
using Aspose.Imaging; using Aspose.Imaging.ImageOptions;namespace CSharp.ModifyingAndConvertingImages.CDR {class CdrToPngExample{static void Main(){// The path to the documents directory.string dataDir = "files";string[] testFiles = new string[] { "Sample.svg" };License lic = new License();lic.SetLicense(dataDir+"License.lic");// Loop through the files array.foreach (string fileName in testFiles){string inputFileName = Path.Combine(dataDir, fileName);string outputFileName = Path.Combine(dataDir, fileName + ".emf");// Load the source SVG file by calling the Image.Load(inputFileName) method. using (Image image = Image.Load(inputFileName)){// Set SVG rasterization options with the same page size as the original image. VectorRasterizationOptions vectorRasterizationOptions = new SvgRasterizationOptions { PageSize = image.Size };// Initialize EMF options and assign the SVG rasterization settings for vector rendering. EmfOptions emfOptions = new EmfOptions{VectorRasterizationOptions = vectorRasterizationOptions};// The Save method will save the resultant EMF file on the disk. image.Save(outputFileName,emfOptions);}}}}}
輸出:
總結
我們探索了一種可靠的方法,可以在 C# 中以編程方式將 SVG 轉換為 EMF。Aspose.Imaging?for .NET是 .NET 開發人員實現自動化轉換的優選方案。此外,這款圖像處理 SDK 賦予程序員完全控制權,使他們能夠根據自身需求擴展功能。這篇博文介紹了其基本功能。