PNG圖像文件格式是廣泛使用的圖像格式之一。這種圖像文件格式提供了增強的共享和顯示功能。另一方面,CMX也是 Corel 應用程序主要使用的圖像文件格式。然而,將 CMX 轉換為 PNG 可以幫助用戶在網絡上查看和共享文件。因此,在本指南中,我們將以編程方式實現此轉換。Aspose.Imaging?for .NET是一款功能強大的 .NET 開發人員 SDK。因此,我們將使用此 SDK,通過編寫幾行源代碼,在 C# 中將 CMX 轉換為 PNG。
Aspose.Imaging for .NET官方正版下載
首先安裝 SDK
設置非常簡單。您可以從此鏈接下載 SDK?。或者,您也可以在程序包管理器控制臺中運行以下命令來安裝它。
Install-Package Aspose.Imaging
使用 C# 將 CMX 轉換為 PNG - 代碼示例
Aspose.Imaging for .NET提供了完整的圖像處理和轉換解決方案。那么,讓我們按照以下步驟開始實施:
- 創建CmxRasterizationOptions類的實例。
- 實例化PngOptions類的對象。
- 通過調用Image.Load方法加載每個 CMX 文件。
- 調用Save方法將文件保存為 PNG 圖像。
以下代碼示例演示了如何在 C# 中將 CMX 轉換為 PNG:
using Aspose.Imaging; using Aspose.Imaging.ImageOptions;namespace CSharp.ModifyingAndConvertingImages.CMX {class CmxToPngExample{static void Main(){// The path to the documents directory.string dataDir = "data";License lic = new License();lic.SetLicense(dataDir+"License.lic");// List of source CMX files.string[] fileNames = new string[] {"Ellipse.cmx"};foreach (string fileName in fileNames){// Create an instance of the CmxRasterizationOptions class. CmxRasterizationOptions cmxRasterizationOptions = new CmxRasterizationOptions(){Positioning = PositioningTypes.DefinedByDocument,SmoothingMode = SmoothingMode.AntiAlias};// Instantiate an object of the PngOptions class. PngOptions pngOptions = new PngOptions{VectorRasterizationOptions = cmxRasterizationOptions};// Load each CMX file by calling the Image.Load method. using (Image image = Image.Load(dataDir + fileName)){// Call the Save method to save the file as PNG image.image.Save(dataDir + fileName + ".docpage.png",pngOptions);}}}} }
輸出:
總結
我們已經介紹了如何使用Aspose.Imaging for .NET在 C# 中將 CMX 轉換為 PNG?。您可以根據需要擴展此 CMX 到 PNG 轉換器。