Packages

 

com.aspose.psd.fileformats.psd.layers

Class Layer

    • Field Detail

      • LayerHeaderSize

        public static final int LayerHeaderSize

        The layer header size.

        See Also:
        Constant Field Values
      • BlendSignature

        public static final int BlendSignature

        Represents blend mode signature.

        See Also:
        Constant Field Values
    • Constructor Detail

      • Layer

        public Layer()

        Initializes a new instance of the Layer class. Constructor for lazy initialization.

      • Layer

        public Layer(RasterImage image,
                     boolean disposeImage)

        Initializes a new instance of the Layer class.

        Parameters:
        image - The image.
        disposeImage - if set to true [dispose image].
      • Layer

        public Layer(InputStream stream)

        Initializes a new instance of the Layer class.

        Parameters:
        stream - The image stream
      • Layer

        public Layer(Rectangle bounds,
                     byte[] redBytes,
                     byte[] greenBytes,
                     byte[] blueBytes,
                     String name)

        Initializes a new instance of the Layer class from byte arrays.

        Parameters:
        bounds - The layer bounds.
        redBytes - The red bytes.
        greenBytes - The green bytes.
        blueBytes - The blue bytes.
        name - The layer name.
        Throws:
        PsdImageException - Byte arrays can not be empty or Byte arrays length must equal bounds dimensions (bounds.getWidth() * bounds.getHeight())
    • Method Detail

      • getResources

        public final LayerResource[] getResources()

        Gets or sets the layer resources.

        Value: The layer resources.
      • setResources

        public final void setResources(LayerResource[] value)

        Gets or sets the layer resources.

        Value: The layer resources.
      • hasAlpha

        public boolean hasAlpha()

        Gets a value indicating whether this instance has alpha.

        Value: true if this instance has alpha; otherwise, false.
        Overrides:
        hasAlpha in class RasterImage
        Returns:
        true if this instance has alpha; otherwise, false.
      • getName

        public final String getName()

        Gets or sets the layer name.

        Value: The layer name.
      • getBlendingOptions

        public final BlendingOptions getBlendingOptions()

        Gets the blending options.

        Value: The blending options.
      • getDisplayName

        public final String getDisplayName()

        Gets the display name of the layer.

        Value: The display name of the layer.
      • setDisplayName

        public final void setDisplayName(String value)

        Gets or sets the display name of the layer.

        Value: The display name of the layer.
      • getFillOpacity

        public final int getFillOpacity()

        Gets or sets the fill opacity.

        Throws:
        PsdImageArgumentException - Fill opacity can be only in the range from 0 to 100 Value: The fill opacity in range from 0 to 100
      • setFillOpacity

        public final void setFillOpacity(int value)

        Gets the fill opacity.

        Throws:
        PsdImageArgumentException - Fill opacity can be only in the range from 0 to 100 Value: The fill opacity in range from 0 to 100
      • getLayerCreationDateTime

        public final Date getLayerCreationDateTime()

        Gets or sets the layer creation date time.

        Value: The layer's creation date time. If there is no data about creation DateTime then returns Unix Time first epoch
      • setLayerCreationDateTime

        public final void setLayerCreationDateTime(Date value)

        Gets or sets the layer creation date time.

        Value: The layer's creation date time. If there is no data about creation DateTime then returns Unix Time first epoch
      • getSheetColorHighlight

        public final short getSheetColorHighlight()

        Gets or sets the decorative sheet color highlight in layers' list

        Value: The sheet color highlight.
      • setSheetColorHighlight

        public final void setSheetColorHighlight(short value)

        Gets or sets the decorative sheet color highlight in layers' list

        Value: The sheet color highlight.
      • getTop

        public final int getTop()

        Gets or sets the top layer position.

        Value: The top layer position.
      • setTop

        public final void setTop(int value)

        Gets or sets the top layer position.

        Value: The top layer position.
      • getLeft

        public final int getLeft()

        Gets or sets the left layer position.

        Value: The left layer position.
      • setLeft

        public final void setLeft(int value)

        Gets or sets the left layer position.

        Value: The left layer position.
      • getBottom

        public final int getBottom()

        Gets or sets the bottom layer position.

        Value: The bottom layer position.
      • setBottom

        public final void setBottom(int value)

        Gets or sets the bottom layer position.

        Value: The bottom layer position.
      • getRight

        public final int getRight()

        Gets or sets the right layer position.

        Value: The right layer position.
      • setRight

        public final void setRight(int value)

        Gets or sets the right layer position.

        Value: The right layer position.
      • getChannelsCount

        public final int getChannelsCount()

        Gets the layer's channels count.

        Value: The layer's channels count.
      • getChannelInformation

        public final ChannelInformation[] getChannelInformation()

        Gets or sets the channel information.

        Value: The channel information.
      • setChannelInformation

        public final void setChannelInformation(ChannelInformation[] value)

        Gets or sets the channel information.

        Value: The channel information.
      • getBlendModeSignature

        public final int getBlendModeSignature()

        Gets the blend mode signature.

        Value: The blend mode signature.
      • getBlendModeKey

        public long getBlendModeKey()

        Gets or sets the blend mode key.

        Value: The blend mode key.
      • setBlendModeKey

        public void setBlendModeKey(long value)

        Gets or sets the blend mode key.

        Value: The blend mode key.
        Code example:

        An example of loading a PSD file containing a layer group with the Pass Through blending mode applied. It loads the PSD file and verifies whether it was correctly read then saves two copies of the original file in the PSD and PNG file formats and two copies in the same file formats with the Normal blending mode applied to the layer group.


                    
        // Keep the methods in the local scope (just to simplify copy-pasting)
        class LocalScopeExtension
        {
            void assertIsTrue(boolean condition, String message)
            {
                if (!condition)
                {
                    throw new FormatException(message);
                }
            }
        }
        LocalScopeExtension $ = new LocalScopeExtension();
                    
        String inPsdFilePath = "Apple.psd";
        String outPsdFilePath = "Output" + inPsdFilePath;
        String outPngFilePath = "OutputApple.png";
        String outPsdFilePath1 = "Normal" + outPsdFilePath;
        String outPngFilePath1 = "Normal" + outPngFilePath;
                    
        // Load a PSD file containing a predefined layer group
        PsdImage psdImage = (PsdImage)Image.load(inPsdFilePath);
        try
        {
            // Make sure the loaded PSD file contains the predefined layer group
            $.assertIsTrue(psdImage.getLayers().length >= 24, "There is not 24rd layer.");
            LayerGroup layerGroup = (LayerGroup)psdImage.getLayers()[23];
            $.assertIsTrue(layerGroup != null, "The 24rd layer is not a layer group.");
            $.assertIsTrue(layerGroup.getName().equals("AdjustmentGroup"), "The 24rd layer name is not 'AdjustmentGroup'.");
            $.assertIsTrue(layerGroup.getBlendModeKey() == BlendMode.PassThrough, "AdjustmentGroup layer should have 'pass through' blend mode.");
                    
            // Save a copy of the loaded PSD file on the specified path
            psdImage.save(outPsdFilePath, new PsdOptions());
                    
            // Save the loaded AI file as a PNG file with a white background
            PngOptions pngOptions = new PngOptions();
            pngOptions.setColorType(PngColorType.TruecolorWithAlpha);
            psdImage.save(outPngFilePath, pngOptions);
                    
            // Change the blending mode for the layer group
            layerGroup.setBlendModeKey(BlendMode.Normal);
                    
            // Save a copy of the loaded PSD file including the changes on the specified path
            psdImage.save(outPsdFilePath1, new PsdOptions());
                    
            // Save the loaded AI file including the changes as a PNG file with a white background
            PngOptions pngOptions1 = new PngOptions();
            pngOptions1.setColorType(PngColorType.TruecolorWithAlpha);
            psdImage.save(outPngFilePath1, pngOptions1);
        }
        finally
        {
            psdImage.dispose();
        }
        

      • getOpacity

        public final byte getOpacity()

        Gets or sets the layer opacity. 0 = transparent, 255 = opaque.

        Value: The layer opacity.
      • setOpacity

        public final void setOpacity(byte value)

        Gets or sets the layer opacity. 0 = transparent, 255 = opaque.

        Value: The layer opacity.
      • getClipping

        public final byte getClipping()

        Gets or sets the layer clipping. 0 = base, 1 = non-base.

        Value: The layer clipping.
      • setClipping

        public final void setClipping(byte value)

        Gets or sets the layer clipping. 0 = base, 1 = non-base.

        Value: The layer clipping.
      • getFlags

        public final byte getFlags()

        Gets or sets the layer flags. bit 0 = transparency protected; bit 1 = visible; bit 2 = obsolete; bit 3 = 1 for Photoshop 5.0 and later, tells if bit 4 has useful information; bit 4 = pixel data irrelevant to appearance of document.

        Value: The layer flags.
      • setFlags

        public final void setFlags(byte value)

        Gets or sets the layer flags. bit 0 = transparency protected; bit 1 = visible; bit 2 = obsolete; bit 3 = 1 for Photoshop 5.0 and later, tells if bit 4 has useful information; bit 4 = pixel data irrelevant to appearance of document.

        Value: The layer flags.
      • getFiller

        public final byte getFiller()

        Gets or sets the layer filler.

        Value: The layer filler.
      • setFiller

        public final void setFiller(byte value)

        Gets or sets the layer filler.

        Value: The layer filler.
      • getLength

        public final int getLength()

        Gets the overall layer length in bytes.

      • getExtraLength

        public final int getExtraLength()

        Gets the layer extra information length in bytes.

        Value: The extra layer length.
      • getLayerMaskData

        public final LayerMaskData getLayerMaskData()

        Gets or sets the layer mask data.

        Value: The layer mask data.
      • setLayerMaskData

        public final void setLayerMaskData(LayerMaskData value)

        Gets or sets the layer mask data.

        Value: The layer mask data.
      • getLayerBlendingRangesData

        public final LayerBlendingRangesData getLayerBlendingRangesData()

        Gets or sets the layer blending ranges data.

        Value: The layer blending ranges data.
      • setLayerBlendingRangesData

        public final void setLayerBlendingRangesData(LayerBlendingRangesData value)

        Gets or sets the layer blending ranges data.

        Value: The layer blending ranges data.
      • getBitsPerPixel

        public int getBitsPerPixel()

        Gets the image bits per pixel count.

        Value: The image bits per pixel count.
        Specified by:
        getBitsPerPixel in class Image
        Returns:
        The image bits per pixel count.
      • getHeight

        public int getHeight()

        Gets the image height.

        Value: The image height.
        Specified by:
        getHeight in interface IObjectWithBounds
        Specified by:
        getHeight in class Image
        Returns:
        The image height.
      • getWidth

        public int getWidth()

        Gets the image width.

        Value: The image width.
        Specified by:
        getWidth in interface IObjectWithBounds
        Specified by:
        getWidth in class Image
        Returns:
        The image width.
      • getLayerOptions

        public final PsdOptions getLayerOptions()

        Gets the layer options.

        Value: The layer options.
      • isVisible

        public final boolean isVisible()

        Gets or sets a value indicating whether the layer is visible

        Value: true if this instance is visible; otherwise, false.
      • setVisible

        public final void setVisible(boolean value)

        Gets or sets a value indicating whether the layer is visible

        Value: true if this instance is visible; otherwise, false.
      • isVisibleInGroup

        public boolean isVisibleInGroup()

        Gets a value indicating whether this instance is visible in group(If layer is not in group it means root group).

        Value: true if this instance is visible in group; otherwise, false.
      • getLayerLock

        public final int getLayerLock()

        Gets or sets the layer lock. Note that if flag LayerFlags.TransparencyProtected is set it will be overwritten by layer lock flag. To return LayerFlags.TransparencyProtected flag need to apply for layer option layer.Flags |= LayerFlags.TransparencyProtected

        Value: The layer lock.
      • setLayerLock

        public final void setLayerLock(int value)

        Gets or sets the layer lock (Note that if flag LayerFlags.TransparencyProtected is set it will be overritten by layer lock flag. To return LayerFlags.TransparencyProtected flag need to apply for layer option layer.Flags |= LayerFlags.TransparencyProtected

        Value: The layer lock.
      • shallowCopy

        public final Layer shallowCopy()

        Creates a shallow copy of the current Layer. Please for explanation.

        Returns:
        A shallow copy of the current Layer.
      • save

        public void save(String filePath,
                         ImageOptionsBase options)

        Saves the object's data to the specified file location in the specified file format according to save options.

        Overrides:
        save in class Image
        Parameters:
        filePath - The file path.
        options - The options.
      • save

        public void save(String filePath,
                         boolean overWrite)

        Saves the object's data to the specified file location.

        Overrides:
        save in class DataStreamSupporter
        Parameters:
        filePath - The file path to save the object's data to.
        overWrite - if set to true over write the file contents, otherwise append will occur.
      • save

        public void save(OutputStream dstStream,
                         ImageOptionsBase optionsBase,
                         Rectangle boundsRectangle)

        Saves the image's data to the specified stream in the specified file format according to save options.

        Overrides:
        save in class Image
        Parameters:
        dstStream - The stream to save the image's data to.
        optionsBase - The save options.
        boundsRectangle - The destination image bounds rectangle. Set the empty rectangle for use sourse bounds.
      • save

        public void save(String filePath,
                         ImageOptionsBase options,
                         Rectangle boundsRectangle)

        Saves the object's data to the specified file location in the specified file format according to save options.

        Overrides:
        save in class Image
        Parameters:
        filePath - The file path.
        options - The options.
        boundsRectangle - The destination image bounds rectangle. Set the empty rectangle for use sourse bounds.
      • equals

        public boolean equals(Object obj)

        Determines whether the specified Object, is equal to this instance.

        Overrides:
        equals in class Object
        Parameters:
        obj - The Object to compare with this instance.
        Returns:
        true if the specified Object is equal to this instance; otherwise, false.
      • hashCode

        public int hashCode()

        Returns a hash code for this instance.

        Overrides:
        hashCode in class Object
        Returns:
        A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
      • addLayerMask

        public final void addLayerMask(LayerMaskData layerMask)

        Adds the mask to current layer.

        Parameters:
        layerMask - The layer mask.
        Throws:
        PsdImageException - Full layer mask is not supported for setting yet, please use LayerMaskDataShort
      • mergeLayerTo

        public void mergeLayerTo(Layer layerToMergeInto)

        Merges the layer to specified layer

        Parameters:
        layerToMergeInto - The layer to merge into.
      • drawImage

        public final void drawImage(Point location,
                                    RasterImage image)

        Draws the image on layer.

        Parameters:
        location - The location.
        image - The image.
        Throws:
        PsdImageException - Location must be non-negative
      • setName

        public final void setName(String name)

        Sets the layer name.

        Parameters:
        name - The layer name.