Packages

 

com.aspose.imaging.fileformats.psd

Class PsdImage

  • All Implemented Interfaces:
    IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, com.aspose.imaging_internal.ILayerableImage, com.aspose.imaging_internal.IPixelsSaver, com.aspose.imaging_internal.progressmanagement.IProgressEventHandler, com.aspose.imaging_internal.progressmanagement.IProgressInformer, com.aspose.ms.System.IDisposable, Closeable, AutoCloseable


    public final class PsdImage
    extends RasterCachedImage
    implements com.aspose.imaging_internal.ILayerableImage

    A PSD image.

    Code example:

    This example shows how to load a PSD image from a file and transforms it to a grayscale image.


    String dir = "c:\\temp\\";
    
    // Load a PSD image.
    com.aspose.imaging.fileformats.psd.PsdImage psdImage = new com.aspose.imaging.fileformats.psd.PsdImage(dir + "simple.psd");
    try {
        // Do some image processing
        psdImage.grayscale();
        psdImage.save(dir + "simple.grayscale.psd");
    } finally {
        psdImage.dispose();
    }
    

    • Field Detail

      • DEFAULT_VERSION

        public static final int DEFAULT_VERSION

        The default PSD version.

        See Also:
        Constant Field Values
    • Constructor Detail

      • PsdImage

        public PsdImage(String path)

        Creates new instance of psd image PsdImage class from specified path from raster image (not psd image in path). Used to initialize psd image with default parameters - Color mode - rgb, 4 channels, 8 bit per channel, Compression - Raw.

        Parameters:
        path - The path to load pixel and palette data from and initialize with.
        Code example:

        This example shows how to load a PSD image from a file and transforms it to a grayscale image.


        String dir = "c:\\temp\\";
        
        // Load a PSD image.
        com.aspose.imaging.fileformats.psd.PsdImage psdImage = new com.aspose.imaging.fileformats.psd.PsdImage(dir + "simple.psd");
        try {
            // Do some image processing
            psdImage.grayscale();
            psdImage.save(dir + "simple.grayscale.psd");
        } finally {
            psdImage.dispose();
        }
        

      • PsdImage

        public PsdImage(String path,
                        short colorMode,
                        short channelBitDepth,
                        short channels,
                        int psdVersion,
                        short compression)

        Creates new instance of psd image PsdImage class from specified path from raster image (not psd image in path) with constructor parameters.

        Parameters:
        path - The path to load pixel and palette data from and initialize with.
        colorMode - The color mode.
        channelBitDepth - The PSD bit depth per channel.
        channels - The PSD channels count.
        psdVersion - The PSD version.
        compression - The compression to use.
        Code example:

        This example shows how to load a PSD image from a file and transforms it to a grayscale 8-bit image.


        String dir = "c:\\temp\\";
        
        // Note that if the source image is colorful, it will be transformed to a 8-bit grayscale image as specified in the arguments.
        com.aspose.imaging.fileformats.psd.PsdImage psdImage = new com.aspose.imaging.fileformats.psd.PsdImage(
                dir + "simple.psd",
                com.aspose.imaging.fileformats.psd.ColorModes.Grayscale,      // The desired color mode
                (short) 8,                                                    // The number of bits per channel
                (short) 1,                                                    // The number of channels
                com.aspose.imaging.fileformats.psd.PsdImage.DEFAULT_VERSION,  // The default version is 6
                com.aspose.imaging.fileformats.psd.CompressionMethod.RLE);    // The RLE compression allows to reduce the size of the output image
        try {
            psdImage.save(dir + "simple.grayscale.psd");
        } finally {
            psdImage.dispose();
        }
        

      • PsdImage

        public PsdImage(InputStream stream)

        Creates new instance of psd image PsdImage class from specified path from raster image (not psd image in stream). Used to initialize psd image with default parameters - Color mode - rgb, 4 channels, 8 bit per channel, Compression - Raw.

        Parameters:
        stream - The stream to load pixel and palette data from and initialize with.
        Code example:

        This example shows how to load a PSD image from a file stream and transforms it to a grayscale image.


        String dir = "c:\\temp\\";
        
        java.io.InputStream stream = new java.io.FileInputStream(dir + "simple.psd");
        com.aspose.imaging.fileformats.psd.PsdImage psdImage = new com.aspose.imaging.fileformats.psd.PsdImage(stream);
        try {
            // Do some image processing
            psdImage.grayscale();
            psdImage.save(dir + "simple.grayscale.psd");
        } finally {
            psdImage.dispose();
            stream.close();
        }
        

      • PsdImage

        public PsdImage(InputStream stream,
                        short colorMode,
                        short channelBitDepth,
                        short channels,
                        int psdVersion,
                        short compression)

        Creates new instance of psd image PsdImage class from specified path from raster image (not psd image in stream) with constructor parameters.

        Parameters:
        stream - The stream to load pixel and palette data from and initialize with.
        colorMode - The color mode.
        channelBitDepth - The PSD bit depth per channel.
        channels - The PSD channels count.
        psdVersion - The PSD version.
        compression - The compression to use.
      • PsdImage

        public PsdImage(RasterImage rasterImage)

        Creates new instance of psd image PsdImage class from existing raster image (not psd image) with RGB color mode with 4 channels 8 bit/channel and no compression.

        Parameters:
        rasterImage - The image to load pixel and palette data from and initialize with.
        Code example:

        This example shows how to load a PSD image from another raster image and transforms it to a grayscale image.


        String dir = "c:\\temp\\";
        
        // A PSD image is built on a PNG image.
        com.aspose.imaging.fileformats.png.PngImage pngImage = new com.aspose.imaging.fileformats.png.PngImage(dir + "sample.png");
        com.aspose.imaging.fileformats.psd.PsdImage psdImage = new com.aspose.imaging.fileformats.psd.PsdImage(pngImage);
        try {
            // Do some image processing.
            psdImage.grayscale();
            psdImage.save(dir + "sample.grayscale.psd");
        } finally {
            psdImage.dispose();
            pngImage.dispose();
        }
        

      • PsdImage

        public PsdImage(RasterImage rasterImage,
                        short colorMode,
                        short channelBitDepth,
                        short channels,
                        int psdVersion,
                        short compression)

        Creates new instance of psd image PsdImage class from existing raster image (not psd image) with constructor parameters.

        Parameters:
        rasterImage - The image to load pixel and palette data from and initialize with.
        colorMode - The color mode.
        channelBitDepth - The PSD bit depth per channel.
        channels - The PSD channels count.
        psdVersion - The PSD version.
        compression - The compression to use.
        Code example:

        This example shows how to load a PSD image from another raster image with specified options and transforms it to a grayscale 8-bit image.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.fileformats.png.PngImage pngImage = new com.aspose.imaging.fileformats.png.PngImage(dir + "sample.png");
        try {
            // Note that if the source image is colorful, it will be transformed to a 8-bit grayscale image as specified in the arguments.
            com.aspose.imaging.fileformats.psd.PsdImage psdImage = new com.aspose.imaging.fileformats.psd.PsdImage(
                    pngImage,
                    com.aspose.imaging.fileformats.psd.ColorModes.Grayscale,     // The desired color mode
                    (short) 8,                                                    // The number of bits per channel
                    (short) 1,                                                    // The number of channels
                    com.aspose.imaging.fileformats.psd.PsdImage.DEFAULT_VERSION, // The default version is 6
                    com.aspose.imaging.fileformats.psd.CompressionMethod.RLE);   // The RLE compression allows to reduce the size of the output image
            try {
                psdImage.save(dir + "sample.grayscale.psd");
            } finally {
                psdImage.dispose();
            }
        } finally {
            pngImage.dispose();
        }
        

      • PsdImage

        public PsdImage(int width,
                        int height)

        Creates new instance of psd image PsdImage class with specified width and height. Used to initialize empty psd image.

        Parameters:
        width - The image width.
        height - The image height.
        Code example:

        This example shows how to create a new PSD image and fill it with a linear gradient brush.


        String dir = "c:\\temp\\";
        
        // Create a PSD image of 100x100 px.
        com.aspose.imaging.fileformats.psd.PsdImage psdImage = new com.aspose.imaging.fileformats.psd.PsdImage(100, 100);
        try {
            // Define a blue-yellow gradient.
            com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush(
                    new com.aspose.imaging.Point(0, 0),
                    new com.aspose.imaging.Point(psdImage.getWidth(), psdImage.getHeight()),
                    com.aspose.imaging.Color.getBlue(),
                    com.aspose.imaging.Color.getYellow());
        
            com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(psdImage);
        
            // Fill the entire image with the blue-yellow gradient.
            graphics.fillRectangle(gradientBrush, psdImage.getBounds());
        
            psdImage.save(dir + "gradient.psd");
        } finally {
            psdImage.dispose();
        }
        

      • PsdImage

        public PsdImage(int width,
                        int height,
                        IColorPalette colorPalette,
                        short colorMode,
                        short channelBitDepth,
                        short channels,
                        int psdVersion,
                        short compression)

        Creates new instance of psd image PsdImage class with specified width,height, paletter, color mode, channels count and channels bit-length and specified compression mode parameters. Used to initialize empty psd image.

        Parameters:
        width - The image width.
        height - The image height.
        colorPalette - The color palette.
        colorMode - The color mode.
        channelBitDepth - The PSD bit depth per channel.
        channels - The PSD channels count.
        psdVersion - The PSD version.
        compression - The compression to use.
        Code example:

        This example shows how to create a grayscale 8-bit PSD image.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.fileformats.psd.PsdImage psdImage = new com.aspose.imaging.fileformats.psd.PsdImage(
                100,                                                        // Width
                100,                                                       // Height
                null,                                              // Without a palette
                com.aspose.imaging.fileformats.psd.ColorModes.Grayscale,      // Desired color mode
                (short) 8,                                                     // Number of bits per channel
                (short) 1,                                                     // Number of channels
                com.aspose.imaging.fileformats.psd.PsdImage.DEFAULT_VERSION,  // Default version is 6
                com.aspose.imaging.fileformats.psd.CompressionMethod.RLE);    // The RLE compression allows to reduce the size of the output image
        {
            // Define a blue-yellow gradient.
            com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush(
                    new com.aspose.imaging.Point(0, 0),
                    new com.aspose.imaging.Point(psdImage.getWidth(), psdImage.getHeight()),
                    com.aspose.imaging.Color.getBlue(),
                    com.aspose.imaging.Color.getYellow());
        
            com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(psdImage);
        
            // Fill the entire image with the blue-yellow gradient.
            // Note that all colors will be transformed to the grayscale format because the image is grayscale.
            graphics.fillRectangle(gradientBrush, psdImage.getBounds());
        
            psdImage.save(dir + "gradient.grayscale.psd");
        }
        

    • Method Detail

      • getFileFormat

        public long getFileFormat()

        Gets a value of file format

        Overrides:
        getFileFormat in class Image
      • hasAlpha

        public boolean hasAlpha()

        Gets the vertical resolution, in pixels per inch, of this RasterImage.

        Value: true if this instance has alpha; otherwise, false.
        Overrides:
        hasAlpha in class RasterImage
        Returns:
        the vertical resolution, in pixels per inch, of this RasterImage.
        Code example:

        The following example loads a PSD image and prints information about raw data format and alpha channel.


        String dir = "c:\\temp\\";
        
        String fileName = dir + "sample.psd";
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(fileName);
        try {
            com.aspose.imaging.fileformats.psd.PsdImage psdImage = (com.aspose.imaging.fileformats.psd.PsdImage) image;
        
            // If at least one of the PSD layers has alpha channel, then the entire PSD image is considered to have alpha channel
            System.out.printf("ImageFile=%s, FileFormat=%s, HasAlpha=%s\r\n", fileName, psdImage.getRawDataFormat(), psdImage.hasAlpha());
        
            int i = 0;
            for (com.aspose.imaging.fileformats.psd.layers.Layer layer : psdImage.getLayers()) {
                System.out.printf("Layer=%s, FileFormat=%s, HasAlpha=%s\r\n", ++i, layer.getRawDataFormat(), layer.hasAlpha());
            }
        } finally {
            image.dispose();
        }
        
        // The output may look like this:
        // ImageFile=c:\temp\sample.psd, FileFormat=Rgb, used channels: 8,8,8, HasAlpha=True
        // Layer=1, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=False
        // Layer=2, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=True
        // Layer=3, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=True
        // Layer=4, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=True
        // Layer=5, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=True
        

      • getVerticalResolution

        public double getVerticalResolution()

        Gets the vertical resolution, in pixels per inch, of this PsdImage.

        Overrides:
        getVerticalResolution in class RasterImage
        Returns:
        The vertical resolution.
        Throws:
        PsdImageException - ResolutionInfo resource not found and can not set proper resolution

        Default value for PSD is 72, so if ResolutionInfoResource wasn't found, this value is returned.

        Code example:

        The following example shows how to set horizontal/vertical resolution of a PSD image.


        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;
        
            // Get horizontal and vertical resolution of the PsdImage.
            double horizontalResolution = psdImage.getHorizontalResolution();
            double verticalResolution = psdImage.getVerticalResolution();
            System.out.println("The horizontal resolution, in pixels per inch: " + horizontalResolution);
            System.out.println("The vertical resolution, in pixels per inch: " + verticalResolution);
        
            if (horizontalResolution != 96.0 || verticalResolution != 96.0) {
                // Use the SetResolution method for updating both resolution values in a single call.
                System.out.println("Set resolution values to 96 dpi");
                psdImage.setResolution(96.0, 96.0);
        
                System.out.println("The horizontal resolution, in pixels per inch: " + psdImage.getHorizontalResolution());
                System.out.println("The vertical resolution, in pixels per inch: " + psdImage.getVerticalResolution());
            }
        } finally {
            image.dispose();
        }
        
        // The output may look like this:
        // The horizontal resolution, in pixels per inch: 72.0
        // The vertical resolution, in pixels per inch: 72.0
        // Set resolution values to 96 dpi
        // The horizontal resolution, in pixels per inch: 72.0
        // The vertical resolution, in pixels per inch: 72.0
        

      • setVerticalResolution

        public void setVerticalResolution(double value)

        Sets the vertical resolution, in pixels per inch, of this PsdImage.

        Overrides:
        setVerticalResolution in class RasterImage
        Parameters:
        value - The vertical resolution.

        Default value for PSD is 72, so if ResolutionInfoResource wasn't found, this value is returned.

        Throws:
        PsdImageException - ResolutionInfo resource not found and can not set proper resolution
      • getHorizontalResolution

        public double getHorizontalResolution()

        Gets the horizontal resolution, in pixels per inch, of this PsdImage.

        Overrides:
        getHorizontalResolution in class RasterImage
        Returns:
        The horizontal resolution.
        Throws:
        PsdImageException - ResolutionInfo resource not found and can not set proper resolution

        Default value for PSD is 72, so if ResolutionInfoResource wasn't found, this value is returned.

        Code example:

        The following example shows how to set horizontal/vertical resolution of a PSD image.


        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;
        
            // Get horizontal and vertical resolution of the PsdImage.
            double horizontalResolution = psdImage.getHorizontalResolution();
            double verticalResolution = psdImage.getVerticalResolution();
            System.out.println("The horizontal resolution, in pixels per inch: " + horizontalResolution);
            System.out.println("The vertical resolution, in pixels per inch: " + verticalResolution);
        
            if (horizontalResolution != 96.0 || verticalResolution != 96.0) {
                // Use the SetResolution method for updating both resolution values in a single call.
                System.out.println("Set resolution values to 96 dpi");
                psdImage.setResolution(96.0, 96.0);
        
                System.out.println("The horizontal resolution, in pixels per inch: " + psdImage.getHorizontalResolution());
                System.out.println("The vertical resolution, in pixels per inch: " + psdImage.getVerticalResolution());
            }
        } finally {
            image.dispose();
        }
        
        // The output may look like this:
        // The horizontal resolution, in pixels per inch: 72.0
        // The vertical resolution, in pixels per inch: 72.0
        // Set resolution values to 96 dpi
        // The horizontal resolution, in pixels per inch: 72.0
        // The vertical resolution, in pixels per inch: 72.0
        

      • setHorizontalResolution

        public void setHorizontalResolution(double value)

        Sets the horizontal resolution, in pixels per inch, of this PsdImage.

        Overrides:
        setHorizontalResolution in class RasterImage
        Parameters:
        value - The horizontal resolution.

        Default value for PSD is 72, so if ResolutionInfoResource wasn't found, this value is returned.

        Throws:
        PsdImageException - ResolutionInfo resource not found and can not set proper resolution
      • getRgbColorProfile

        public StreamSource getRgbColorProfile()

        The RGB color profile for CMYK PSD images. Must be in pair with CmykColorProfile for correct color conversion.

        Returns:
        The RGB color profile.
      • setRgbColorProfile

        public void setRgbColorProfile(StreamSource value)

        The RGB color profile for CMYK PSD images. Must be in pair with CmykColorProfile for correct color conversion.

        Parameters:
        value - The RGB color profile.
      • getCmykColorProfile

        public StreamSource getCmykColorProfile()

        The CMYK color profile for CMYK PSD images. Must be in pair with RgbColorProfile for correct color conversion.

        Returns:
        The CMYK color profile.
      • setCmykColorProfile

        public void setCmykColorProfile(StreamSource value)

        The CMYK color profile for CMYK PSD images. Must be in pair with RgbColorProfile for correct color conversion.

        Parameters:
        value - The CMYK color profile.
      • getGrayColorProfile

        public StreamSource getGrayColorProfile()

        The GRAY (monochrome) color profile for Grayscale PSD images.

        Returns:
        The GRAY (monochrome) color profile.
      • setGrayColorProfile

        public void setGrayColorProfile(StreamSource value)

        The GRAY (monochrome) color profile for Grayscale PSD images.

        Parameters:
        value - The GRAY (monochrome) color profile.
      • getColorMode

        public short getColorMode()

        Gets the color mode.

        Returns:
        The color mode.
      • setColorMode

        public void setColorMode(short value)

        Sets the color mode.

        Parameters:
        value - The color mode.
      • getCompression

        public short getCompression()

        Gets the compression method.

        Returns:
        The compression.
      • getChannelsCount

        public int getChannelsCount()

        Gets the PSD channels count.

        Returns:
        The PSD channels count.
      • getBitsPerChannel

        public int getBitsPerChannel()

        Gets the bits per channel.

        Returns:
        The bits per channel.
      • getImageResources

        public ResourceBlock[] getImageResources()

        Gets the PSD image resources.

        Returns:
        The PSD image resources.
      • setImageResources

        public void setImageResources(ResourceBlock[] value)

        Sets the PSD image resources.

        Parameters:
        value - The PSD image resources.
      • getVersion

        public int getVersion()

        Gets the version.

        Returns:
        The version.
      • setVersion

        public void setVersion(int value)

        Sets the version.

        Parameters:
        value - The version.
      • getBitsPerPixel

        public int getBitsPerPixel()

        Gets the image bits per pixel count.

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

        public Layer[] getLayers()

        Gets the PSD layers.

        Returns:
        The PSD layers.

        Note that if there are no layers the other related information within layer and mask information section will not be preserved (layer masks, resources and etc).

      • setLayers

        public void setLayers(Layer[] value)

        Sets the PSD layers.

        Parameters:
        value - The PSD layers.

        Note that if there are no layers the other related information within layer and mask information section will not be preserved (layer masks, resources and etc).

      • getGlobalLayerResources

        public LayerResource[] getGlobalLayerResources()

        Gets the global layer resources.

        Returns:
        The global layer resources.
      • setGlobalLayerResources

        public void setGlobalLayerResources(LayerResource[] value)

        Sets the global layer resources.

        Parameters:
        value - The global layer resources.
      • getGlobalLayerMaskInfo

        public GlobalLayerMaskInfo getGlobalLayerMaskInfo()

        Gets the global layer mask info.

      • hasTransparencyData

        public boolean hasTransparencyData()

        Gets or sets a value indicating whether first alpha channel contains the transparency data for the merged result when specifying layers data.

        Returns:
        true if first alpha channel contains the transparency data for the merged result when specifying layers data; otherwise, false.
      • setTransparencyData

        public void setTransparencyData(boolean value)

        Sets a value indicating whether first alpha channel contains the transparency data for the merged result when specifying layers data.

        Parameters:
        value - true if first alpha channel contains the transparency data for the merged result when specifying layers data; otherwise, false.
      • getActiveLayer

        public Layer getActiveLayer()

        Gets the active layer.

        Returns:
        The active layer.
        Throws:
        TiffImageException - There is no active layer and no layers in image.
        PsdImageException - The active layer cannot be set as it belongs to another image.
      • setActiveLayer

        public void setActiveLayer(Layer value)

        Sets the active layer.

        Parameters:
        value - The active layer.
        Throws:
        TiffImageException - There is no active layer and no layers in image.
        PsdImageException - The active layer cannot be set as it belongs to another image.
      • isFlatten

        public boolean isFlatten()

        Gets a value indicating whether psd image is flattened.

        Returns:
        true if this instance is flatten; otherwise, false.
      • getRawDataFormat

        public PixelDataFormat getRawDataFormat()

        Gets the raw data format.

        Overrides:
        getRawDataFormat in class RasterImage
        Returns:
        The raw data format.
        Code example:

        The following example loads a PSD image and prints information about raw data format and alpha channel.


        String dir = "c:\\temp\\";
        
        String fileName = dir + "sample.psd";
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(fileName);
        try {
            com.aspose.imaging.fileformats.psd.PsdImage psdImage = (com.aspose.imaging.fileformats.psd.PsdImage) image;
        
            // If at least one of the PSD layers has alpha channel, then the entire PSD image is considered to have alpha channel
            System.out.printf("ImageFile=%s, FileFormat=%s, HasAlpha=%s\r\n", fileName, psdImage.getRawDataFormat(), psdImage.hasAlpha());
        
            int i = 0;
            for (com.aspose.imaging.fileformats.psd.layers.Layer layer : psdImage.getLayers()) {
                System.out.printf("Layer=%s, FileFormat=%s, HasAlpha=%s\r\n", ++i, layer.getRawDataFormat(), layer.hasAlpha());
            }
        } finally {
            image.dispose();
        }
        
        // The output may look like this:
        // ImageFile=c:\temp\sample.psd, FileFormat=Rgb, used channels: 8,8,8, HasAlpha=True
        // Layer=1, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=False
        // Layer=2, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=True
        // Layer=3, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=True
        // Layer=4, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=True
        // Layer=5, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=True
        

      • addLayer

        public final void addLayer(Layer layer)

        Adds the layer.

        Parameters:
        layer - The layer.
      • mergeLayers

        public final Layer mergeLayers(Layer bottomLayer,
                                       Layer topLayer)

        Merges the layers.

        Parameters:
        bottomLayer - The bottom layer.
        topLayer - The top layer.
        Returns:
        Bottom layer after the merge
      • flattenImage

        public final void flattenImage()

        Flattens all layers.

        Code example:

        This example shows how to add two general-purpose layers to a PSD image and then join them into one layer.


        String dir = "c:\\temp\\";
        
        // Create a PSD image of 100x100 px.
        com.aspose.imaging.fileformats.psd.PsdImage psdImage = new com.aspose.imaging.fileformats.psd.PsdImage(
                100,                                                        // Width
                100,                                                       // Height
                null,                                               // Without a palette
                com.aspose.imaging.fileformats.psd.ColorModes.Rgb,            // Desired color mode
                (short) 8,                                                     // Number of bits per channel
                (short) 4,                                                     // Number of channels, R,G,B + Alpha
                com.aspose.imaging.fileformats.psd.PsdImage.DEFAULT_VERSION,  // Default version is 6
                com.aspose.imaging.fileformats.psd.CompressionMethod.RLE);    // The RLE compression allows to reduce the size of the output image
        {
            // Add a new regular layer. This layer will be in front of the back layer.
            com.aspose.imaging.fileformats.psd.layers.Layer frontLayer = psdImage.addRegularLayer();
        
            // Define a blue-transparent gradient.
            com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush(
                    new com.aspose.imaging.Point(0, 0),
                    new com.aspose.imaging.Point(frontLayer.getWidth(), frontLayer.getHeight()),
                    com.aspose.imaging.Color.getBlue(),
                    com.aspose.imaging.Color.getTransparent());
        
            com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(frontLayer);
        
            // Fill the first layer with the blue-transparent gradient.
            graphics.fillRectangle(gradientBrush, frontLayer.getBounds());
        
            // Add a new regular layer. This layer will be behind the front layer.
            com.aspose.imaging.fileformats.psd.layers.Layer backLayer = psdImage.addRegularLayer();
        
            com.aspose.imaging.Graphics graphics2 = new com.aspose.imaging.Graphics(backLayer);
        
            // Define a yellow-transparent gradient.
            com.aspose.imaging.brushes.LinearGradientBrush gradientBrush2 = new com.aspose.imaging.brushes.LinearGradientBrush(
                    new com.aspose.imaging.Point(backLayer.getWidth(), 0),
                    new com.aspose.imaging.Point(0, backLayer.getHeight()),
                    com.aspose.imaging.Color.getYellow(),
                    com.aspose.imaging.Color.getTransparent());
        
            // Fill the second layer with the yellow-transparent gradient.
            graphics2.fillRectangle(gradientBrush2, backLayer.getBounds());
        
            // Merge all the image's layers into one layer.
            psdImage.flattenImage();
        
            psdImage.save(dir + "flatten.psd");
        }
        

      • addRegularLayer

        public final Layer addRegularLayer()

        Adds a new regular layer.

        Returns:
        Created regular layer.
        Code example:

        This example shows how to add two general-purpose layers to a PSD image and then join them into one layer.


        String dir = "c:\\temp\\";
        
        // Create a PSD image of 100x100 px.
        com.aspose.imaging.fileformats.psd.PsdImage psdImage = new com.aspose.imaging.fileformats.psd.PsdImage(
                100,                                                        // Width
                100,                                                       // Height
                null,                                               // Without a palette
                com.aspose.imaging.fileformats.psd.ColorModes.Rgb,            // Desired color mode
                (short) 8,                                                     // Number of bits per channel
                (short) 4,                                                     // Number of channels, R,G,B + Alpha
                com.aspose.imaging.fileformats.psd.PsdImage.DEFAULT_VERSION,  // Default version is 6
                com.aspose.imaging.fileformats.psd.CompressionMethod.RLE);    // The RLE compression allows to reduce the size of the output image
        {
            // Add a new regular layer. This layer will be in front of the back layer.
            com.aspose.imaging.fileformats.psd.layers.Layer frontLayer = psdImage.addRegularLayer();
        
            // Define a blue-transparent gradient.
            com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush(
                    new com.aspose.imaging.Point(0, 0),
                    new com.aspose.imaging.Point(frontLayer.getWidth(), frontLayer.getHeight()),
                    com.aspose.imaging.Color.getBlue(),
                    com.aspose.imaging.Color.getTransparent());
        
            com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(frontLayer);
        
            // Fill the first layer with the blue-transparent gradient.
            graphics.fillRectangle(gradientBrush, frontLayer.getBounds());
        
            // Add a new regular layer. This layer will be behind the front layer.
            com.aspose.imaging.fileformats.psd.layers.Layer backLayer = psdImage.addRegularLayer();
        
            com.aspose.imaging.Graphics graphics2 = new com.aspose.imaging.Graphics(backLayer);
        
            // Define a yellow-transparent gradient.
            com.aspose.imaging.brushes.LinearGradientBrush gradientBrush2 = new com.aspose.imaging.brushes.LinearGradientBrush(
                    new com.aspose.imaging.Point(backLayer.getWidth(), 0),
                    new com.aspose.imaging.Point(0, backLayer.getHeight()),
                    com.aspose.imaging.Color.getYellow(),
                    com.aspose.imaging.Color.getTransparent());
        
            // Fill the second layer with the yellow-transparent gradient.
            graphics2.fillRectangle(gradientBrush2, backLayer.getBounds());
        
            // Merge all the image's layers into one layer.
            psdImage.flattenImage();
        
            psdImage.save(dir + "flatten.psd");
        }
        

      • addTextLayer

        public final TextLayer addTextLayer(String text,
                                            Rectangle rect)

        Adds a new Text layer.

        Parameters:
        text - The layer's text.
        rect - The layer's rectangle.
        Returns:
        Created text layer.
        Code example:

        This example shows how to add a text layer to a PSD image.


        String dir = "c:\\temp\\";
        
        // Create a PSD image of 100x100 px.
        com.aspose.imaging.fileformats.psd.PsdImage psdImage = new com.aspose.imaging.fileformats.psd.PsdImage(100, 100);
        try {
            com.aspose.imaging.fileformats.psd.layers.TextLayer textLayer = psdImage.addTextLayer("Hello World!", psdImage.getBounds());
            psdImage.save(dir + "textlayer.psd");
        } finally {
            psdImage.dispose();
        }
        

      • addCurvesAdjustmentLayer

        public final CurvesLayer addCurvesAdjustmentLayer()

        Adds the Curves Adjustment layer.

        Returns:
        Created CurvesLayer Layer
      • addExposureAdjustmentLayer

        public final ExposureLayer addExposureAdjustmentLayer()
      • addExposureAdjustmentLayer

        public final ExposureLayer addExposureAdjustmentLayer(float exposure)
      • addExposureAdjustmentLayer

        public final ExposureLayer addExposureAdjustmentLayer(float exposure,
                                                              float offset)
      • addExposureAdjustmentLayer

        public final ExposureLayer addExposureAdjustmentLayer(float exposure,
                                                              float offset,
                                                              float gammaCorrection)

        Adds the exposure adjustment layer.

        Parameters:
        exposure - The exposure.
        offset - The offset.
        gammaCorrection - The gamma correction.
        Returns:
        Created Exposure Adjustment Layer
      • addHueSaturationAdjustmentLayer

        public final HueSaturationLayer addHueSaturationAdjustmentLayer()

        Adds the hue/saturation adjustment layer.

        Returns:
        A newly created hue/saturation layer.
      • addLevelsAdjustmentLayer

        public final LevelsLayer addLevelsAdjustmentLayer()

        Adds the Levels adjustment layer.

        Returns:
        A newly created Levels layer
      • addPhotoFilterLayer

        public final PhotoFilterLayer addPhotoFilterLayer(Color color)

        Adds the photofilter layer.

        Parameters:
        color - The color.
        Returns:
        Created PhotoFilter Layer
      • addExposureLayer

        public final ExposureLayer addExposureLayer()
      • addExposureLayer

        public final ExposureLayer addExposureLayer(float exposure)
      • addExposureLayer

        public final ExposureLayer addExposureLayer(float exposure,
                                                    float offset)
      • addExposureLayer

        public final ExposureLayer addExposureLayer(float exposure,
                                                    float offset,
                                                    float gammaCorrection)

        Adds the exposure adjustment layer.

        Parameters:
        exposure - The exposure.
        offset - The offset.
        gammaCorrection - The gamma correction.
        Returns:
        Created Exposure Adjustment Layer
      • addChannelMixerAdjustmentLayer

        public final ChannelMixerLayer addChannelMixerAdjustmentLayer()

        Adds the channel mixer adjustment layer with default parameters

        Returns:
        Added Channel Mixer Layer
      • addBrightnessContrastAdjustmentLayer

        public final BrightnessContrastLayer addBrightnessContrastAdjustmentLayer(int brightness,
                                                                                  int contrast)

        Adds the brightness/contrast adjustment layer.

        Parameters:
        brightness - The brightness.
        contrast - The contrast.
        Returns:
        Created brightness/contrast layer
      • addLayerGroup

        public LayerGroup addLayerGroup(String groupName,
                                        int index,
                                        boolean startBehaviour)

        Adds the layer group.

        Parameters:
        groupName - Name of the group.
        index - The index of the layer to insert after.
        startBehaviour - if set to true [start behaviour] than group will be in open state on start up, otherwise in minimized state.
        Returns:
        Opening group layer
      • rotate

        public void rotate(float angle)

        Rotate image around the center.

        Overrides:
        rotate in class RasterImage
        Parameters:
        angle - The rotate angle in degrees. Positive values will rotate clockwise.
      • rotate

        public void rotate(float angle,
                           boolean resizeProportionally,
                           Color backgroundColor)

        Rotate image around the center.

        Overrides:
        rotate in class RasterCachedImage
        Parameters:
        angle - The rotate angle in degrees. Positive values will rotate clockwise.
        resizeProportionally - if set to true you will have your image size changed according to rotated rectangle (corner points) projections in other case that leaves dimensions untouched and only internal image contents are rotated.
        backgroundColor - Color of the background.
      • crop

        public void crop(Rectangle rectangle)

        Cropping the image.

        Overrides:
        crop in class RasterCachedImage
        Parameters:
        rectangle - The rectangle.
      • resizeHeightProportionally

        public void resizeHeightProportionally(int newHeight,
                                               ImageResizeSettings settings)

        Resizes the height proportionally.

        Overrides:
        resizeHeightProportionally in class Image
        Parameters:
        newHeight - The new height.
        settings - The image resize settings.
      • resizeHeightProportionally

        public void resizeHeightProportionally(int newHeight,
                                               int resizeType)

        Resizes the height proportionally.

        Overrides:
        resizeHeightProportionally in class Image
        Parameters:
        newHeight - The new height.
        resizeType - Type of the resize.
        Code example:

        This example loads a PSD image and resizes it proportionally using various resizing methods. Only the height is specified, the width is calculated automatically.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.fileformats.psd.PsdImage image = (com.aspose.imaging.fileformats.psd.PsdImage) com.aspose.imaging.Image.load(dir + "sample.psd");
        try {
            // Scale up by 2 times using Nearest Neighbour resampling.
            image.resizeHeightProportionally(image.getHeight() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
        
            // Save to PNG with the default options.
            image.save(dir + "upsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            image.dispose();
        }
        
        image = (com.aspose.imaging.fileformats.psd.PsdImage) com.aspose.imaging.Image.load(dir + "sample.psd");
        try {
            // Scale down by 2 times using Nearest Neighbour resampling.
            image.resizeHeightProportionally(image.getHeight() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
        
            // Save to PNG with the default options.
            image.save(dir + "downsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            image.dispose();
        }
        
        image = (com.aspose.imaging.fileformats.psd.PsdImage) com.aspose.imaging.Image.load(dir + "sample.psd");
        try {
            // Scale up by 2 times using Bilinear resampling.
            image.resizeHeightProportionally(image.getHeight() * 2, com.aspose.imaging.ResizeType.BilinearResample);
        
            // Save to PNG with the default options.
            image.save(dir + "upsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            image.dispose();
        }
        
        image = (com.aspose.imaging.fileformats.psd.PsdImage) com.aspose.imaging.Image.load(dir + "sample.psd");
        try {
            // Scale down by 2 times using Bilinear resampling.
            image.resizeHeightProportionally(image.getHeight() / 2, com.aspose.imaging.ResizeType.BilinearResample);
        
            // Save to PNG with the default options.
            image.save(dir + "downsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            image.dispose();
        }
        

      • resizeWidthProportionally

        public void resizeWidthProportionally(int newWidth,
                                              ImageResizeSettings settings)

        Resizes the width proportionally.

        Overrides:
        resizeWidthProportionally in class Image
        Parameters:
        newWidth - The new width.
        settings - The image resize settings.
      • resizeWidthProportionally

        public void resizeWidthProportionally(int newWidth,
                                              int resizeType)

        Resizes the width proportionally.

        Overrides:
        resizeWidthProportionally in class Image
        Parameters:
        newWidth - The new width.
        resizeType - Type of the resize.
        Code example:

        This example loads a PSD image and resizes it proportionally using various resizing methods. Only the width is specified, the height is calculated automatically.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.fileformats.psd.PsdImage image = (com.aspose.imaging.fileformats.psd.PsdImage) com.aspose.imaging.Image.load(dir + "sample.psd");
        try {
            // Scale up by 2 times using Nearest Neighbour resampling.
            image.resizeWidthProportionally(image.getWidth() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
        
            // Save to PNG with the default options.
            image.save(dir + "upsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            image.dispose();
        }
        
        image = (com.aspose.imaging.fileformats.psd.PsdImage) com.aspose.imaging.Image.load(dir + "sample.psd");
        try {
            // Scale down by 2 times using Nearest Neighbour resampling.
            image.resizeWidthProportionally(image.getWidth() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
        
            // Save to PNG with the default options.
            image.save(dir + "downsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            image.dispose();
        }
        
        image = (com.aspose.imaging.fileformats.psd.PsdImage) com.aspose.imaging.Image.load(dir + "sample.psd");
        try {
            // Scale up by 2 times using Bilinear resampling.
            image.resizeWidthProportionally(image.getWidth() * 2, com.aspose.imaging.ResizeType.BilinearResample);
        
            // Save to PNG with the default options.
            image.save(dir + "upsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            image.dispose();
        }
        
        image = (com.aspose.imaging.fileformats.psd.PsdImage) com.aspose.imaging.Image.load(dir + "sample.psd");
        try {
            // Scale down by 2 times using Bilinear resampling.
            image.resizeWidthProportionally(image.getWidth() / 2, com.aspose.imaging.ResizeType.BilinearResample);
        
            // Save to PNG with the default options.
            image.save(dir + "downsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            image.dispose();
        }
        

      • dither

        public void dither(int ditheringMethod,
                           int bitsCount,
                           IColorPalette customPalette)

        Performs dithering on the current image.

        Overrides:
        dither in class RasterCachedImage
        Parameters:
        ditheringMethod - The dithering method.
        bitsCount - The final bits count for dithering.
        customPalette - The custom palette for dithering.
      • binarizeBradley

        public void binarizeBradley(double brightnessDifference,
                                    int windowSize)

        Binarization of an image using Bradley's adaptive thresholding algorithm using the integral image thresholding

        Overrides:
        binarizeBradley in class RasterCachedImage
        Parameters:
        brightnessDifference - The brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.
        windowSize - The size of s x s window of pixels centered around this pixel
      • binarizeBradley

        public void binarizeBradley(double brightnessDifference)

        Binarization of an image using Bradley's adaptive thresholding algorithm using the integral image thresholding

        Overrides:
        binarizeBradley in class RasterCachedImage
        Parameters:
        brightnessDifference - The brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.
      • adjustBrightness

        public void adjustBrightness(int brightness)

        Adjust of a brightness for image.

        Overrides:
        adjustBrightness in class RasterCachedImage
        Parameters:
        brightness - Brightness value.
      • adjustGamma

        public void adjustGamma(float gamma)

        Gamma-correction of an image.

        Overrides:
        adjustGamma in class RasterCachedImage
        Parameters:
        gamma - Gamma for red, green and blue channels coefficient
      • adjustContrast

        public void adjustContrast(float contrast)

        Image contrasting

        Overrides:
        adjustContrast in class RasterCachedImage
        Parameters:
        contrast - Contrast value (in range [-100; 100])
      • adjustGamma

        public void adjustGamma(float gammaRed,
                                float gammaGreen,
                                float gammaBlue)

        Gamma-correction of an image.

        Overrides:
        adjustGamma in class RasterCachedImage
        Parameters:
        gammaRed - Gamma for red channel coefficient
        gammaGreen - Gamma for green channel coefficient
        gammaBlue - Gamma for blue channel coefficient
      • binarizeFixed

        public void binarizeFixed(byte threshold)

        Binarization of an image with predefined threshold

        Overrides:
        binarizeFixed in class RasterCachedImage
        Parameters:
        threshold - Threshold value. If corresponding gray value of a pixel is greater than threshold, a value of 255 will be assigned to it, 0 otherwise.
      • grayscale

        public void grayscale()

        Transformation of an image to its grayscale representation

        Overrides:
        grayscale in class RasterCachedImage
      • filter

        public void filter(Rectangle rectangle,
                           FilterOptionsBase options)

        Filters the specified rectangle.

        Overrides:
        filter in class RasterImage
        Parameters:
        rectangle - The rectangle.
        options - The options.
        Code example:

        The following example applies various types of filters to a PSD image.


        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;
        
            // Apply a median filter with a rectangle size of 5 to the entire image.
            psdImage.filter(psdImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.MedianFilterOptions(5));
            psdImage.save(dir + "sample.MedianFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            image.dispose();
        }
        
        image = com.aspose.imaging.Image.load(dir + "sample.psd");
        try {
            com.aspose.imaging.fileformats.psd.PsdImage psdImage = (com.aspose.imaging.fileformats.psd.PsdImage) image;
        
            // Apply a bilateral smoothing filter with a kernel size of 5 to the entire image.
            psdImage.filter(psdImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.BilateralSmoothingFilterOptions(5));
            psdImage.save(dir + "sample.BilateralSmoothingFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            image.dispose();
        }
        
        image = com.aspose.imaging.Image.load(dir + "sample.psd");
        try {
            com.aspose.imaging.fileformats.psd.PsdImage psdImage = (com.aspose.imaging.fileformats.psd.PsdImage) image;
        
            // Apply a Gaussian blur filter with a radius of 5 and a sigma value of 4.0 to the entire image.
            psdImage.filter(psdImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.GaussianBlurFilterOptions(5, 4.0));
            psdImage.save(dir + "sample.GaussianBlurFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            image.dispose();
        }
        
        image = com.aspose.imaging.Image.load(dir + "sample.psd");
        try {
            com.aspose.imaging.fileformats.psd.PsdImage psdImage = (com.aspose.imaging.fileformats.psd.PsdImage) image;
        
            // Apply a Gauss-Wiener filter with a radius of 5 and a smooth value of 4.0 to the entire image.
            psdImage.filter(psdImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.GaussWienerFilterOptions(5, 4.0));
            psdImage.save(dir + "sample.GaussWienerFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            image.dispose();
        }
        
        image = com.aspose.imaging.Image.load(dir + "sample.psd");
        try {
            com.aspose.imaging.fileformats.psd.PsdImage psdImage = (com.aspose.imaging.fileformats.psd.PsdImage) image;
        
            // Apply a motion wiener filter with a length of 5, a smooth value of 4.0 and an angle of 90.0 degrees to the entire image.
            psdImage.filter(psdImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.MotionWienerFilterOptions(10, 1.0, 90.0));
            psdImage.save(dir + "sample.MotionWienerFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            image.dispose();
        }
        
        image = com.aspose.imaging.Image.load(dir + "sample.psd");
        try {
            com.aspose.imaging.fileformats.psd.PsdImage psdImage = (com.aspose.imaging.fileformats.psd.PsdImage) image;
        
            // Apply a sharpen filter with a kernel size of 5 and a sigma value of 4.0 to the entire image.
            psdImage.filter(psdImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.SharpenFilterOptions(5, 4.0));
            psdImage.save(dir + "sample.SharpenFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            image.dispose();
        }
        

      • replaceColor

        public void replaceColor(int oldColorArgb,
                                 byte oldColorDiff,
                                 int newColorArgb)

        Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.

        Overrides:
        replaceColor in class RasterImage
        Parameters:
        oldColorArgb - Old color ARGB value to be replaced.
        oldColorDiff - Allowed difference in old color to be able to widen replaced color tone.
        newColorArgb - New color ARGB value to replace old color with.
      • replaceNonTransparentColors

        public void replaceNonTransparentColors(int newColorArgb)

        Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges. Note: if you use it on images without transparency, all colors will be replaced with a single one.

        Overrides:
        replaceNonTransparentColors in class RasterImage
        Parameters:
        newColorArgb - New color ARGB value to replace non transparent colors with.