Packages

 

com.aspose.imaging.fileformats.psd.layers

Class Layer

    • Field Detail

      • LAYER_HEADER_SIZE

        public static final int LAYER_HEADER_SIZE

        The layer header size.

        See Also:
        Constant Field Values
      • BLEND_SIGNATURE

        public static final int BLEND_SIGNATURE

        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)

        Initializes a new instance of the Layer class.

        Parameters:
        image - The image.
      • 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 dimentions (bounds.Width * bounds.Height)
    • Method Detail

      • shallowCopy

        public Layer shallowCopy()

        Creates a shallow copy of the current Layer. Please see https://msdn.microsoft.com/ru-ru/library/system.object.memberwiseclone(v=vs.110).aspx for explanation.

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

        public LayerResource[] getResources()

        Gets or sets the layer resources.

        Value: The layer resources.
      • setResources

        public void setResources(LayerResource[] value)

        Gets or sets the layer resources.

        Value: The layer resources.
      • getName

        public String getName()

        Gets or sets the layer name.

        Value: The layer name.
      • setName

        public void setName(String value)

        Gets or sets the layer name.

        Value: The layer name.
      • getBlendingOptions

        public final BlendingOptions getBlendingOptions()

        Gets the blending options.

        Value: The blending options.
        Returns:
        the blending options.
      • getDisplayName

        public String getDisplayName()

        Gets the display name of the layer.

        Value: The display name of the layer.
      • getFillOpacity

        public final int getFillOpacity()

        Gets the fill opacity.

        Returns:
        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)

        The fill opacity.

        Parameters:
        value - 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 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
        Returns:
        the layer creation date time.
      • setLayerCreationDateTime

        public final void setLayerCreationDateTime(Date value)

        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
        Parameters:
        value - the layer creation date time.
      • getSheetColorHighlight

        public final short getSheetColorHighlight()

        Gets the decorative sheet color highlight in layers' list

        Value: The sheet color highlight.
        Returns:
        the decorative sheet color highlight in layers' list
      • setSheetColorHighlight

        public final void setSheetColorHighlight(short value)

        Sets the decorative sheet color highlight in layers' list

        Value: The sheet color highlight.
        Parameters:
        value - the decorative sheet color highlight in layers' list
      • getTop

        public int getTop()

        Gets or sets the top layer position.

        Value: The top layer position.
      • setTop

        public void setTop(int value)

        Gets or sets the top layer position.

        Value: The top layer position.
      • getLeft

        public int getLeft()

        Gets or sets the left layer position.

        Value: The left layer position.
      • setLeft

        public void setLeft(int value)

        Gets or sets the left layer position.

        Value: The left layer position.
      • getBottom

        public int getBottom()

        Gets or sets the bottom layer position.

        Value: The bottom layer position.
      • setBottom

        public void setBottom(int value)

        Gets or sets the bottom layer position.

        Value: The bottom layer position.
      • getRight

        public int getRight()

        Gets or sets the right layer position.

        Value: The right layer position.
      • setRight

        public void setRight(int value)

        Gets or sets the right layer position.

        Value: The right layer position.
      • getChannelsCount

        public int getChannelsCount()

        Gets the layer's channels count.

        Value: The layer's channels count.
      • getChannelInformation

        public ChannelInformation[] getChannelInformation()

        Gets or sets the channel information.

        Value: The channel information.
      • setChannelInformation

        public void setChannelInformation(ChannelInformation[] value)

        Gets or sets the channel information.

        Value: The channel information.
      • getBlendModeSignature

        public int getBlendModeSignature()

        Gets the blend mode signature.

        Returns:
        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.
      • getOpacity

        public byte getOpacity()

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

        Value: The layer opacity.
      • setOpacity

        public void setOpacity(byte value)

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

        Value: The layer opacity.
      • getClipping

        public byte getClipping()

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

        Value: The layer clipping.
      • setClipping

        public void setClipping(byte value)

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

        Value: The layer clipping.
      • getFlags

        public 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 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 byte getFiller()

        Gets or sets the layer filler.

        Value: The layer filler.
      • setFiller

        public void setFiller(byte value)

        Gets or sets the layer filler.

        Value: The layer filler.
      • getLength

        public int getLength()

        Gets the overall layer length in bytes.

      • getExtraLength

        public int getExtraLength()

        Gets the layer extra information length in bytes.

        Returns:
        The extra layer length.
      • getLayerMaskData

        public LayerMaskData getLayerMaskData()

        Gets or sets the layer mask data.

        Value: The layer mask data.
      • setLayerMaskData

        public void setLayerMaskData(LayerMaskData value)

        Gets or sets the layer mask data.

        Value: The layer mask data.
      • getLayerBlendingRangesData

        public LayerBlendingRangesData getLayerBlendingRangesData()

        Gets or sets the layer blending ranges data.

        Value: The layer blending ranges data.
      • setLayerBlendingRangesData

        public 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 PsdOptions getLayerOptions()

        Gets the layer options.

        Returns:
        The layer options.
      • isVisible

        public boolean isVisible()

        Gets or sets a value indicating whether the layer is visible

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

        public 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 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

        Returns:
        The layer lock.
      • setLayerLock

        public void setLayerLock(int value)

        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

        Parameters:
        value - The layer lock.
      • hasAlpha

        public boolean hasAlpha()

        Gets a value indicating whether this instance has alpha.

        Overrides:
        hasAlpha in class RasterImage
        Returns:
        true if this instance has alpha; otherwise, false.
      • 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.
        Code example:

        The following example loads a PSD image from a file, then saves the PSD image to a PNG file.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.psd");
        try {
            com.aspose.imaging.fileformats.psd.PsdImage psdImage = (com.aspose.imaging.fileformats.psd.PsdImage) image;
        
            // Save each layer in a separate PNG file with the default options.
            int i = 0;
            com.aspose.imaging.imageoptions.PngOptions saveOptions = new com.aspose.imaging.imageoptions.PngOptions();
            for (com.aspose.imaging.fileformats.psd.layers.Layer layer : psdImage.getLayers()) {
                // Some types of layers cannot be exported to raster format.
                if (layer instanceof com.aspose.imaging.fileformats.psd.layers.LayerGroup ||
                        layer instanceof com.aspose.imaging.fileformats.psd.layers.adjustmentlayers.AdjustmentLayer) {
                    continue;
                }
        
                layer.save(dir + "output." + (++i) + ".png", saveOptions);
            }
        } finally {
            image.dispose();
        }
        

      • 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(com.aspose.ms.System.IO.Stream stream,
                         ImageOptionsBase optionsBase,
                         Rectangle boundsRectangle)

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

        Parameters:
        stream - 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.
        Code example:

        The following example loads a PSD image from a file, then saves a rectangular part of the PSD image to a PNG file.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.psd");
        try {
            com.aspose.imaging.fileformats.psd.PsdImage psdImage = (com.aspose.imaging.fileformats.psd.PsdImage) image;
        
            // Save the upper-left quarter of each layer in a separate PNG file with the default options.
            int i = 0;
            com.aspose.imaging.imageoptions.PngOptions saveOptions = new com.aspose.imaging.imageoptions.PngOptions();
            for (com.aspose.imaging.fileformats.psd.layers.Layer layer : psdImage.getLayers()) {
                // Some types of layers cannot be exported to raster format.
                if (layer instanceof com.aspose.imaging.fileformats.psd.layers.LayerGroup ||
                        layer instanceof com.aspose.imaging.fileformats.psd.layers.adjustmentlayers.AdjustmentLayer) {
                    continue;
                }
        
                com.aspose.imaging.Rectangle bounds = new com.aspose.imaging.Rectangle(0, 0, layer.getWidth() / 2, layer.getHeight() / 2);
                layer.save(dir + "output." + (++i) + ".png", saveOptions, bounds);
            }
        } finally {
            image.dispose();
        }
        

      • equals

        public boolean equals(Object obj)

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

        Overrides:
        equals in class Object
        Parameters:
        obj - The System.Object to compare with this instance.
        Returns:
        true if the specified System.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 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 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
      • getLayerBounds

        public Rectangle getLayerBounds()

        Gets bounds of the layer which can be different from bounds of image container in general case.

        Specified by:
        getLayerBounds in interface com.aspose.imaging_internal.ILayer
        Returns:
        The rectangular boundaries.