处理Adobe Illustrator格式

将AI文件导出为PSD

使用Aspose.PSD for .NET,开发人员可以将Adobe Illustrator文件转换为PSD格式。本主题解释了加载现有AI文件并使用PsdOptions类将其转换为PSD的方法。

将AI文件转换为PSD的步骤如下:

  • 创建AiImage实例,并使用Image类的Load方法加载图像
  • 创建PsdOptions类的实例
  • 使用目标路径和PsdOptions的实例调用AiImage.Save方法

下面提供的示例代码演示了如何将AI导出为PSD。

// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET
{
@"34992OStroke",
@"rect2_color",
};
for (int i = 0; i < sourcesFiles.Length; i++)
{
string name = sourcesFiles[i];
string sourceFileName = dataDir + name + ".ai";
string outFileName = dataDir + name + ".psd";
using (AiImage image = (AiImage)Image.Load(sourceFileName))
{
ImageOptionsBase options = new PsdOptions();
image.Save(outFileName, options);
}
}

将AI文件导出为JPEG

使用Aspose.PSD for .NET,开发人员可以将Adobe Illustrator文件转换为JPEG格式。本主题解释了加载现有AI文件并使用JpegOptions类将其转换为JPEG的方法。

将AI文件转换为JPEG的步骤如下:

  • 创建AiImage实例,并使用Image类的Load方法加载图像
  • 创建JpegOptions类的实例
  • 设置图像的质量
  • 使用目标路径和JpegOptions的实例调用AiImage.Save方法

下面提供的示例代码演示了如何将AI导出为JPEG。

// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET
{
@"34992OStroke",
@"rect2_color",
};
for (int i = 0; i < sourcesFiles.Length; i++)
{
string name = sourcesFiles[i];
string sourceFileName = dataDir + name + ".ai";
string outFileName = dataDir + name + ".jpg";
using (AiImage image = (AiImage)Image.Load(sourceFileName))
{
ImageOptionsBase options = new JpegOptions() { Quality = 85 };
image.Save(outFileName, options);
}
}

将AI文件导出为GIF

Aspose.PSD for .NET提供了AiImage类来加载Adobe Illustrator文件,同样可以用于将AI文件导出为GIF格式。该示例演示了如何使用Aspose.PSD for .NET API来将AI文件导出为GIF图像。

// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET
string[] sourcesFiles = new string[]
{
@"34992OStroke",
@"rect2_color",
};
for (int i = 0; i < sourcesFiles.Length; i++)
{
string name = sourcesFiles[i];
string sourceFileName = dataDir + name + ".ai";
string outFileName = dataDir + name + ".gif";
using (AiImage image = (AiImage)Image.Load(sourceFileName))
{
ImageOptionsBase options = new GifOptions() { DoPaletteCorrection = false };
image.Save(outFileName, options);
}
}

将AI文件导出为PNG

使用Aspose.PSD for .NET,开发人员可以将Adobe Illustrator文件转换为PNG格式。本主题解释了加载现有AI文件并使用PngOptions类将其转换为PNG的方法。

将AI文件转换为PNG的步骤如下:

  • 创建AiImage实例,并使用Image类的Load方法加载图像
  • 创建PngOptions类的实例
  • 设置颜色类型
  • 使用目标路径和PngOptions的实例调用AiImage.Save方法

下面提供的示例代码演示了如何将AI导出为PNG。

// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET
string[] sourcesFiles = new string[]
{
@"34992OStroke",
@"rect2_color",
};
for (int i = 0; i < sourcesFiles.Length; i++)
{
string name = sourcesFiles[i];
string sourceFileName = dataDir + name + ".ai";
string outFileName = dataDir + name + ".png";
using (AiImage image = (AiImage)Image.Load(sourceFileName))
{
ImageOptionsBase options = new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha };
image.Save(outFileName, options);
}
}

将AI文件导出为TIFF

Aspose.PSD for .NET提供了AiImage类来加载Adobe Illustrator文件,同样可以用于将AI文件导出为TIFF格式。该示例演示了如何使用Aspose.PSD for .NET API来将AI文件导出为TIFF图像。

// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET
string[] sourcesFiles = new string[]
{
@"34992OStroke",
@"rect2_color",
};
for (int i = 0; i < sourcesFiles.Length; i++)
{
string name = sourcesFiles[i];
string sourceFileName = dataDir + name + ".ai";
string outFileName = dataDir + name + ".tif";
using (AiImage image = (AiImage)Image.Load(sourceFileName))
{
ImageOptionsBase options = new TiffOptions(TiffExpectedFormat.TiffDeflateRgba);
image.Save(outFileName, options);
}
}

Illustrator中的光栅图像

Aspose.PSD for .NET现在支持Adobe Illustrator格式文件中的光栅图像。以下代码演示了如何加载Adobe Illustrator格式文件中光栅图像的设置。

// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET
void AssertIsTrue(bool condition, string message)
{
if (!condition)
{
throw new FormatException(message);
}
}
string sourceFile = dataDir + "sample.ai";
using (AiImage image = (AiImage)Image.Load(sourceFile))
{
AiLayerSection layer = image.Layers[0];
AssertIsTrue(layer.RasterImages != null, "RasterImages property should be not null");
AssertIsTrue(layer.RasterImages.Length == 1, "RasterImages property should contain exactly one item");
AiRasterImageSection rasterImage = layer.RasterImages[0];
AssertIsTrue(rasterImage.Pixels != null, "rasterImage.Pixels property should be not null");
AssertIsTrue(rasterImage.Pixels.Length == 100, "rasterImage.Pixels property should contain exactly 100 items");
AssertIsTrue((uint)rasterImage.Pixels[99] == 0xFFB21616, "rasterImage.Pixels[99] should be 0xFFB21616");
AssertIsTrue((uint)rasterImage.Pixels[19] == 0xFF00FF00, "rasterImage.Pixels[19] should be 0xFF00FF00");
AssertIsTrue((uint)rasterImage.Pixels[10] == 0xFF01FD00, "rasterImage.Pixels[10] should be 0xFF01FD00");
AssertIsTrue((uint)rasterImage.Pixels[0] == 0xFF0000FF, "rasterImage.Pixels[0] should be 0xFF0000FF");
AssertIsTrue(Math.Abs(0.999875 - rasterImage.Width) < DefaultTolerance, "rasterImage.Width should be 0.99987");
AssertIsTrue(Math.Abs(0.999875 - rasterImage.Height) < DefaultTolerance, "rasterImage.Height should be 0.99987");
AssertIsTrue(Math.Abs(387 - rasterImage.OffsetX) < DefaultTolerance, "rasterImage.OffsetX should be 387");
AssertIsTrue(Math.Abs(379 - rasterImage.OffsetY) < DefaultTolerance, "rasterImage.OffsetY should be 379");
AssertIsTrue(Math.Abs(0 - rasterImage.Angle) < DefaultTolerance, "rasterImage.Angle should be 0");
AssertIsTrue(Math.Abs(0 - rasterImage.LeftBottomShift) < DefaultTolerance, "rasterImage.LeftBottomShift should be 0");
AssertIsTrue(Math.Abs(0 - rasterImage.ImageRectangle.X) < DefaultTolerance, "rasterImage.ImageRectangle.X should be 0");
AssertIsTrue(Math.Abs(0 - rasterImage.ImageRectangle.Y) < DefaultTolerance, "rasterImage.ImageRectangle.Y should be 0");
AssertIsTrue(Math.Abs(10 - rasterImage.ImageRectangle.Width) < DefaultTolerance, "rasterImage.ImageRectangle.Width should be 10");
AssertIsTrue(Math.Abs(10 - rasterImage.ImageRectangle.Height) < DefaultTolerance, "rasterImage.ImageRectangle.Height should be 10");
}