Packages

 

com.aspose.psd.fileformats.ai

Class AiLayerSection



  • public final class AiLayerSection
    extends AiDataSection

    The Ai format Layer Section

    Code example:

    An example of exporting an AI file that contains layers to other file formats. The program loads predefined AI file and verifies one before further exporting.


    class LocalScopeExtension
    {
        void assertIsTrue(boolean condition, String message)
        {
            if (!condition)
            {
                throw new FormatException(message);
            }
        }
    }
    LocalScopeExtension $ = new LocalScopeExtension();
                
    String inAiFilePath = "form_8_2l3_7.ai";
    String outPsdFilePath = "form_8_2l3_7_export.psd";
    String outPngFilePath = "form_8_2l3_7_export.png";
                
    // Load an AI file containing predefined layers
    AiImage aiImage = (AiImage)Image.load(inAiFilePath);
    try
    {
        // Check that AI layers were read correctly
        AiLayerSection layer0 = aiImage.getLayers()[0];
        $.assertIsTrue(layer0 != null, "Layer 0 should be not null.");
        $.assertIsTrue(layer0.getName().equals("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.getDimValue() == 51, "The DimValue property of the layer 0 should be 51.");
        $.assertIsTrue(layer0.getColorNumber() == 0, "The ColorNumber property of the layer 0 should be 0.");
        $.assertIsTrue(layer0.getRed() == 79, "The Red property of the layer 0 should be 79.");
        $.assertIsTrue(layer0.getGreen() == 128, "The Green property of the layer 0 should be 128.");
        $.assertIsTrue(layer0.getBlue() == 255, "The Blue property of the layer 0 should be 255.");
        $.assertIsTrue(layer0.getRasterImages().length == 0, "The pixels length property of the raster image in the layer 0 should equals 0.");
                
        AiLayerSection layer1 = aiImage.getLayers()[1];
        $.assertIsTrue(layer1 != null, "Layer 1 should be not null.");
        $.assertIsTrue(layer1.getName().equals("Layer 1"), "The Name property of the layer 1 should be `Layer 1`");
        $.assertIsTrue(layer1.getRasterImages().length == 1, "The length property of the raster images in the layer 1 should equals 1.");
                
        AiRasterImageSection rasterImage = layer1.getRasterImages()[0];
        $.assertIsTrue(rasterImage != null, "The raster image in the layer 1 should be not null.");
        $.assertIsTrue(rasterImage.getPixels() != null, "The pixels property of the raster image in the layer 1 should be not null.");
        $.assertIsTrue("".equals(rasterImage.getName()), "The Name property of the raster image in the layer 1 should be empty");
        $.assertIsTrue(rasterImage.getPixels().length == 100, "The pixels length property of the raster image in the layer 1 should equals 100.");
                
        // Export to a PSD file
        aiImage.save(outPsdFilePath, new PsdOptions());
                
        // Export to a PNG file with a white background
        PngOptions pngOptions = new PngOptions();
        pngOptions.setColorType(PngColorType.TruecolorWithAlpha);
        aiImage.save(outPngFilePath, pngOptions);
    }
    finally
    {
        aiImage.dispose();
    }
    

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void addRasterImage(AiRasterImageSection rasterImage)
      Adds the raster image.
      int getBlue()
      Gets or sets the blue color component.
      int getColorNumber()
      Gets or sets the color number.
      int getDimValue()
      Gets or sets the dim value as percentage.
      int getGreen()
      Gets or sets the green color component.
      String getName()
      Gets or sets the layer name.
      AiRasterImageSection[] getRasterImages()
      Gets the raster images.
      int getRed()
      Gets or sets the red color component.
      boolean isImagesDimmed()
      Gets or sets a value indicating whether this layer is dimmed.
      boolean isLocked()
      Gets or sets a value indicating whether this layer is locked.
      boolean isPreview()
      Gets or sets a value indicating whether this layer is preview.
      boolean isPrinted()
      Gets or sets a value indicating whether this layer is printed.
      boolean isShown()
      Gets or sets a value indicating whether this layer is shown.
      boolean isTemplate()
      Gets or sets a value indicating whether this layer is a template layer.
      void setBlue(int value)
      Gets or sets the blue color component.
      void setColorNumber(int value)
      Gets or sets the color number.
      void setDimValue(int value)
      Gets or sets the dim value as percentage.
      void setGreen(int value)
      Gets or sets the green color component.
      void setImagesDimmed(boolean value)
      Gets or sets a value indicating whether this layer is dimmed.
      void setLocked(boolean value)
      Gets or sets a value indicating whether this layer is locked.
      void setName(String value)
      Gets or sets the layer name.
      void setPreview(boolean value)
      Gets or sets a value indicating whether this layer is preview.
      void setPrinted(boolean value)
      Gets or sets a value indicating whether this layer is printed.
      void setRed(int value)
      Gets or sets the red color component.
      void setShown(boolean value)
      Gets or sets a value indicating whether this layer is shown.
      void setTemplate(boolean value)
      Gets or sets a value indicating whether this layer is a template layer.
    • Method Detail

      • isTemplate

        public final boolean isTemplate()

        Gets or sets a value indicating whether this layer is a template layer.

        Value: true if this layer is a template; otherwise, false.
      • setTemplate

        public final void setTemplate(boolean value)

        Gets or sets a value indicating whether this layer is a template layer.

        Value: true if this layer is a template; otherwise, false.
      • isLocked

        public final boolean isLocked()

        Gets or sets a value indicating whether this layer is locked. Prevents changes to the item.

        Value: true if this layer is locked; otherwise, false.
      • setLocked

        public final void setLocked(boolean value)

        Gets or sets a value indicating whether this layer is locked. Prevents changes to the item.

        Value: true if this layer is locked; otherwise, false.
      • isShown

        public final boolean isShown()

        Gets or sets a value indicating whether this layer is shown. Displays all artwork contained in the layer on the artboard if true.

        Value: true if this layer is shown; otherwise, false.
      • setShown

        public final void setShown(boolean value)

        Gets or sets a value indicating whether this layer is shown. Displays all artwork contained in the layer on the artboard if true.

        Value: true if this layer is shown; otherwise, false.
      • isPrinted

        public final boolean isPrinted()

        Gets or sets a value indicating whether this layer is printed. Makes the artwork contained in the layer printable if true.

        Value: true if this layer is printed; otherwise, false.
      • setPrinted

        public final void setPrinted(boolean value)

        Gets or sets a value indicating whether this layer is printed. Makes the artwork contained in the layer printable if true.

        Value: true if this layer is printed; otherwise, false.
      • isPreview

        public final boolean isPreview()

        Gets or sets a value indicating whether this layer is preview. Displays the artwork contained in the layer in color instead of as outlines.

        Value: true if this layer is preview; otherwise, false.
      • setPreview

        public final void setPreview(boolean value)

        Gets or sets a value indicating whether this layer is preview. Displays the artwork contained in the layer in color instead of as outlines.

        Value: true if this layer is preview; otherwise, false.
      • isImagesDimmed

        public final boolean isImagesDimmed()

        Gets or sets a value indicating whether this layer is dimmed. Reduces the intensity of linked images and bitmap images contained in the layer.

        Value: true if this layer is dimmed; otherwise, false.
      • setImagesDimmed

        public final void setImagesDimmed(boolean value)

        Gets or sets a value indicating whether this layer is dimmed. Reduces the intensity of linked images and bitmap images contained in the layer.

        Value: true if this layer is dimmed; otherwise, false.
      • getDimValue

        public final int getDimValue()

        Gets or sets the dim value as percentage. Reduces the intensity of linked images and bitmap images contained in the layer to the specified percentage.

        Value: The dim value as percentage.
      • setDimValue

        public final void setDimValue(int value)

        Gets or sets the dim value as percentage. Reduces the intensity of linked images and bitmap images contained in the layer to the specified percentage.

        Value: The dim value as percentage.
      • getName

        public final String getName()

        Gets or sets the layer name. Specifies the name of the item as it appears in the Layers panel.

        Value: The layer name.
      • setName

        public final void setName(String value)

        Gets or sets the layer name. Specifies the name of the item as it appears in the Layers panel.

        Value: The layer name.
      • getColorNumber

        public final int getColorNumber()

        Gets or sets the color number. -1 is the custom color value from Red, Green, Blue properties. Specifies the layer’s color setting.

        Value: The color number.
      • setColorNumber

        public final void setColorNumber(int value)

        Gets or sets the color number. -1 is the custom color value from Red, Green, Blue properties. Specifies the layer’s color setting.

        Value: The color number.
      • getRed

        public final int getRed()

        Gets or sets the red color component.

        Value: The red color component.
      • setRed

        public final void setRed(int value)

        Gets or sets the red color component.

        Value: The red color component.
      • getGreen

        public final int getGreen()

        Gets or sets the green color component.

        Value: The green color component.
      • setGreen

        public final void setGreen(int value)

        Gets or sets the green color component.

        Value: The green color component.
      • getBlue

        public final int getBlue()

        Gets or sets the blue color component.

        Value: The blue color component.
      • setBlue

        public final void setBlue(int value)

        Gets or sets the blue color component.

        Value: The blue color component.
      • getRasterImages

        public final AiRasterImageSection[] getRasterImages()

        Gets the raster images.

        Value: The raster images.
      • addRasterImage

        public final void addRasterImage(AiRasterImageSection rasterImage)

        Adds the raster image.

        Parameters:
        rasterImage - The raster image.