Manipulating Adobe Illustrator Formats
Exporting AI File to PSD
Using Aspose.PSD for .NET, developers can convert Adobe Illustrator file to PSD format. This topic explains the approach to load existing AI file and convert it to PSD using PsdOptions class.
The steps to convert AI file to PSD are as simple as below:
- Create an instance of the AiImage and load image using Load method of Image class
- Create an instance of PsdOptions class
- Call AiImage.Save method with destination path and an instance of PsdOptions
Below the provided sample code demonstrates how to export AI to 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); | |
} | |
} |
Exporting AI File to JPEG
Using Aspose.PSD for .NET, developers can convert Adobe Illustrator file to JPEG format. This topic explains the approach to load the existing AI file and convert it to JPEG using the JpegOptions class.
The steps to convert AI file to JPEG are as simple as below:
- Create an instance of the AiImage and load image using Load method of Image class
- Create an instance of JpegOptions class
- Set image quality
- Call AiImage.Save method with destination path and an instance of JpegOptions
Below provided sample code demonstrate how to export AI to 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); | |
} | |
} |
Exporting AI File to GIF
Aspose.PSD for .NET provides the AiImage class to load Adobe Illustrator files and same can be used to export the AI file to GIF format. This example demonstrates the usage of Aspose.PSD for .NET API to export a AI file to GIF image.
// 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); | |
} | |
} |
Exporting AI File to PNG
Using Aspose.PSD for .NET, developers can convert Adobe Illustrator file to PNG format. This topic explains the approach to load the existing AI file and convert it to PNG using PngOptions class.
The steps to convert AI file to PNG are as simple as below:
- Create an instance of the AiImage and load the image using Load method of Image class
- Create an instance of PngOptions class
- Set the type of color
- Call AiImage.Save method with destination path and an instance of PngOptions
Below provided sample code demonstrates how to export AI to 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); | |
} | |
} |
Exporting AI File to TIFF
Aspose.PSD for .NET provides the AiImage class to load Adobe Illustrator files and same can be used to export the AI file to TIFF format. This example demonstrates the usage of Aspose.PSD for .NET API to export a AI file to TIFF image.
// 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); | |
} | |
} |
Raster Images in Illustrator
Aspose.PSD for .NET now supports Raster images in Adobe Illustrator format files. The following code demonstrates how to load settings of Raster Images in Adobe Illustrator Format Files.
// 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"); | |
} |