Packages

 

com.aspose.psd.fileformats.psd.layers

Class LayerGroup

  • All Implemented Interfaces:
    IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader


    public class LayerGroup
    extends Layer

    Group layer class

    Code example:

    An example of hiding inner layers for each layer group in a PSD file.


                
    String inPsdFileName = "input.psd";
    String outPsdFileName = "output.psd";
                
    // Load a PSD file containing layers' hierarchy
    PsdImage psdImage = (PsdImage)Image.load(inPsdFileName);
    try
    {
        // Hide containing layers for each layer group
        for (Layer layer : psdImage.getLayers())
        {
            if (layer instanceof LayerGroup)
            {
                layer.setVisible(false);
            }
        }
                
        // Save a copy of the loaded PSD file including the changes on the specified path
        psdImage.save(outPsdFileName);
    }
    finally
    {
        psdImage.dispose();
    }
    

    • Method Detail

      • getBlendModeKey

        public long getBlendModeKey()

        Gets or sets the blend mode key.

        Value: The blend mode key.
        Overrides:
        getBlendModeKey in class Layer
      • setBlendModeKey

        public void setBlendModeKey(long value)

        Gets or sets the blend mode key.

        Value: The blend mode key.
        Overrides:
        setBlendModeKey in class Layer
      • getLayers

        public final Layer[] getLayers()

        Gets the layers in layer group

      • addLayer

        public final void addLayer(Layer layer)

        Adds the layer to the layer group.

        Parameters:
        layer - The layer.
      • addLayer

        public final void addLayer(Layer layer,
                                   int index)

        Adds the layer to the layer group.

        Parameters:
        layer - The layer.
        index - The index at which the layer will be inserted. Invalid values mean the end of the layers list.
      • addLayerGroup

        public final LayerGroup addLayerGroup(String groupName,
                                              int index)

        Adds the layer group.

        Parameters:
        groupName - Name of the group.
        index - The index of the layer to insert after.
        Returns:
        Opening group layer
        Code example:

        This example demonstrates how to add a nested layer group to PSD programmatically.


        String dstPsdPath = "output.psd";
                    
        // Create an image with the size of 1x1 pixels to work with
        PsdImage psdImage = new PsdImage(1, 1);
        try
        {
            // Add a parent layer group ("true" means to open the layer group on start)
            LayerGroup group1 = psdImage.addLayerGroup("Group 1", 0, true);
            // Add a nested layer group
            LayerGroup group2 = group1.addLayerGroup("Group 2", 0);
                    
            if (group1.getLayers().length != 2)
            {
                throw new RuntimeException("Group 1 must contain two layers of Group 2.");
            }
                    
            // Verify that there are no exceptions on saving just created layer groups
            psdImage.save(dstPsdPath);
        }
        finally
        {
            psdImage.dispose();
        }