如何在 C# 中将 AI 转换为 PNG

本主题涉及如何在 C# 中AI 转换为 PNG。此应用程序可用于使用 C# 快速将 AI 另存为 PNG,并且可用于 Windows、macOS 或 Linux 内的任何 .NET 配置环境。

在 C# 中将 AI 导出为 PNG 的步骤

  1. 通过从 NuGet 安装 Aspose.PSD for .NET 建立您的环境,将 AI 文件转换为 PNG 图像
  2. 创建 AiImage 类的实例以从磁盘访问源 AI 文件
  3. 初始化 PngOptions 类对象以设置所需的输出 PNG 属性
  4. 将 AI 文件转换为磁盘上的 PNG

通过使用 C# Adobe Illustrator 到 PNG 图像转换应用程序,可以使用上述逐步过程创建,其中该过程将通过从磁盘加载源 Adobe Illustrator (AI) 文件来启动。然后在 PngOptions 类实例的帮助下,将设置所需输出 PNG 图像文件的各种属性,然后使用 Save 方法将 Adobe Illustrator 文件作为 PNG 图像保存在磁盘上。

在 C# 中将 AI 导出到 PNG 的代码

using System;
using Aspose.PSD;
using Aspose.PSD.FileFormats.Ai;
using Aspose.PSD.FileFormats.Png;
using Aspose.PSD.ImageOptions;
namespace TestPSD
{
public class AiToPNG
{
public static void ConvertAiToPng()
{
String path = @"/Users/Documents/KBase/TestData/";
// Applying product license to convert AI to a PNG image in C#
License AiToPngLic = new License();
AiToPngLic.SetLicense(path + "Conholdate.Total.Product.Family.lic");
using (var aitoPngImage = (AiImage)Image.Load(path + "sample3.ai"))
{
//Set the output PNG options
PngOptions pngOpts = new PngOptions();
pngOpts.ResolutionSettings = new ResolutionSetting(800, 800);
pngOpts.ColorType = PngColorType.TruecolorWithAlpha;
pngOpts.BitDepth = 32;
// Save the converted PNG image on the disk
aitoPngImage.Save(path + "PsdConverted.jpg", pngOpts);
}
}
}
}

上面的示例代码演示了使用 C#* 将 *Adobe Illustrator 转换为 PNG 的过程,其中 Image.Load() 方法指的是从磁盘访问源 AI 文件。 PngOptions 类实例用于设置输出 PNG 图像选项,例如分辨率设置、PNG 颜色类型和位深度等等。设置 PNG 属性后,PNG 图像将保存在磁盘上或 MemoryStream 中。

在这个简单的主题中,我们重点介绍了使用 C#* 逐步将 AI 转换为 PNG 的过程。如果您想了解如何将 AI 转换为 PDF 文件,请参阅 如何在 C# 中将 AI 转换为 PDF 上的文章。

 简体中文