Manipulowanie formatami Adobe Illustrator

Eksportowanie pliku AI do PSD

Za pomocą Aspose.PSD dla .NET, programiści mogą konwertować plik programu Adobe Illustrator do formatu PSD. Ten temat wyjaśnia podejście do ładowania istniejącego pliku AI i konwertowania go na PSD za pomocą klasy PsdOptions.

Kroki konwertowania pliku AI na PSD są proste:

  • Utwórz instancję obrazu AiImage i załaduj obraz za pomocą metody Load klasy Image
  • Utwórz instancję klasy PsdOptions
  • Wywołaj metodę AiImage.Save z ścieżką docelową oraz instancją PsdOptions

Poniżej przekazany kod demonstruje, jak eksportować AI do 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);
}
}

Eksportowanie pliku AI do JPEG

Za pomocą Aspose.PSD dla .NET, programiści mogą konwertować plik programu Adobe Illustrator do formatu JPEG. Ten temat wyjaśnia podejście do ładowania istniejącego pliku AI i konwertowania go na JPEG za pomocą klasy JpegOptions.

Kroki konwertowania pliku AI na JPEG są proste:

  • Utwórz instancję obrazu AiImage i załaduj obraz za pomocą metody Load klasy Image
  • Utwórz instancję klasy JpegOptions
  • Ustaw jakość obrazu
  • Wywołaj metodę Save klasy AiImage z ścieżką docelową oraz instancją JpegOptions

Poniżej przekazany kod demonstruje, jak eksportować AI do formatu 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);
}
}

Eksportowanie pliku AI do GIF

Aspose.PSD dla .NET dostarcza klasę AiImage do ładowania plików programu Adobe Illustrator, która może być również używana do eksportowania pliku AI do formatu GIF. Ten przykład demonstruje użycie interfejsu API Aspose.PSD dla .NET do eksportowania pliku AI do obrazu 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);
}
}

Eksportowanie pliku AI do PNG

Za pomocą Aspose.PSD dla .NET, programiści mogą konwertować plik programu Adobe Illustrator do formatu PNG. Ten temat wyjaśnia podejście do ładowania istniejącego pliku AI i konwertowania go na PNG za pomocą klasy PngOptions.

Kroki konwertowania pliku AI na PNG są proste:

  • Utwórz instancję obrazu AiImage i załaduj obraz za pomocą metody Load klasy Image
  • Utwórz instancję klasy PngOptions
  • Ustaw rodzaj koloru
  • Wywołaj metodę AiImage.Save z ścieżką docelową oraz instancją PngOptions

Poniżej przekazany kod demonstruje, jak eksportować AI do formatu 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);
}
}

Eksportowanie pliku AI do TIFF

Aspose.PSD dla .NET dostarcza klasę AiImage do ładowania plików programu Adobe Illustrator, która może być również używana do eksportowania pliku AI do formatu TIFF. Ten przykład demonstruje użycie interfejsu API Aspose.PSD dla .NET do eksportowania pliku AI do obrazu 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);
}
}

Obrazy rastrowe w programie Illustrator

Aspose.PSD dla .NET teraz obsługuje obrazy rastrowe w plikach w formacie Adobe Illustrator. Poniższy kod demonstruje, jak załadować ustawienia obrazów rastrowych w plikach w formacie 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");
}