public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AI(); //ExStart:AIToGIF 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); } } //ExEnd:AIToGIF }
public static void Run() { //ExStart:AIToPNG // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AI(); 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); } } //ExEnd:AIToPNG }
public static void Run() { //ExStart:AIToTIFF // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AI(); 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); } } //ExEnd:AIToTIFF }
public static void Run() { string dataDir = RunExamples.GetDataDir_AI(); string OutputDir = RunExamples.GetDataDir_Output(); //ExStart //ExSummary:The following example demonstrates support of layers in AI format files. string sourceFilePath = Path.Combine(dataDir, "form_8_2l3_7.ai"); string outputFilePath = Path.Combine(OutputDir, "form_8_2l3_7_export"); void AssertIsTrue(bool condition, string message) { if (!condition) { throw new FormatException(message); } } using (AiImage image = (AiImage)Image.Load(sourceFilePath)) { AiLayerSection layer0 = image.Layers[0]; AssertIsTrue(layer0 != null, "Layer 0 should be not null."); AssertIsTrue(layer0.Name == "Layer 4", "The Name property of the layer 0 should be `Layer 4`"); AssertIsTrue(!layer0.IsTemplate, "The IsTemplate property of the layer 0 should be false."); AssertIsTrue(layer0.IsLocked, "The IsLocked property of the layer 0 should be true."); AssertIsTrue(layer0.IsShown, "The IsShown property of the layer 0 should be true."); AssertIsTrue(layer0.IsPrinted, "The IsPrinted property of the layer 0 should be true."); AssertIsTrue(!layer0.IsPreview, "The IsPreview property of the layer 0 should be false."); AssertIsTrue(layer0.IsImagesDimmed, "The IsImagesDimmed property of the layer 0 should be true."); AssertIsTrue(layer0.DimValue == 51, "The DimValue property of the layer 0 should be 51."); AssertIsTrue(layer0.ColorNumber == 0, "The ColorNumber property of the layer 0 should be 0."); AssertIsTrue(layer0.Red == 79, "The Red property of the layer 0 should be 79."); AssertIsTrue(layer0.Green == 128, "The Green property of the layer 0 should be 128."); AssertIsTrue(layer0.Blue == 255, "The Blue property of the layer 0 should be 255."); AssertIsTrue(layer0.RasterImages.Length == 0, "The pixels length property of the raster image in the layer 0 should equals 0."); AiLayerSection layer1 = image.Layers[1]; AssertIsTrue(layer1 != null, "Layer 1 should be not null."); AssertIsTrue(layer1.Name == "Layer 1", "The Name property of the layer 1 should be `Layer 1`"); AssertIsTrue(layer1.RasterImages.Length == 1, "The length property of the raster images in the layer 1 should equals 1."); AiRasterImageSection rasterImage = layer1.RasterImages[0]; AssertIsTrue(rasterImage != null, "The raster image in the layer 1 should be not null."); AssertIsTrue(rasterImage.Pixels != null, "The pixels property of the raster image in the layer 1 should be not null."); AssertIsTrue(string.Empty == rasterImage.Name, "The Name property of the raster image in the layer 1 should be empty"); AssertIsTrue(rasterImage.Pixels.Length == 100, "The pixels length property of the raster image in the layer 1 should equals 100."); image.Save(outputFilePath + ".psd", new PsdOptions()); image.Save(outputFilePath + ".png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); } //ExEnd }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AI(); //ExStart:SupportOfRasterImagesInAI const double DefaultTolerance = 1e-6; 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"); } //ExEnd:SupportOfRasterImagesInAI }