
PNG图像文件格式是广泛使用的图像格式之一。这种图像文件格式提供了增强的共享和显示功能。另一方面,CMX也是 Corel 应用程序主要使用的图像文件格式。然而,将 CMX 转换为 PNG 可以帮助用户在网络上查看和共享文件。因此,在本指南中,我们将以编程方式实现此转换。++Aspose.Imaging++ **++for .NET++**是一款功能强大的 .NET 开发人员 SDK。因此,我们将使用此 SDK,通过编写几行源代码,在 C# 中将 CMX 转换为 PNG。
首先安装 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 转换器。