Packages

 

com.aspose.imaging.fileformats.psd

Class PsdImage

  • All Implemented Interfaces:
    IMultipageImage, 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 RasterCachedMultipageImage
    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 RasterCachedMultipageImage
        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.
      • 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.
      • hasTransparentColor

        public boolean hasTransparentColor()

        Gets a value indicating whether image has transparent color.

        Overrides:
        hasTransparentColor in class RasterCachedMultipageImage
        Returns:
        a value indicating whether image has transparent color.
      • 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.
      • getImageOpacity

        public float getImageOpacity()

        Gets opacity of this image.

        Value: The opacity value between 0.0 (fully transparent) and 1.0 (fully opaque).
        Overrides:
        getImageOpacity in class RasterCachedMultipageImage
        Returns:
        opacity of this image.
      • 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
      • resizeWidthProportionally

        public void resizeWidthProportionally(int newWidth,
                                              int resizeType)

        Resizes the width proportionally.

        Overrides:
        resizeWidthProportionally in class RasterCachedMultipageImage
        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();
        }
        

      • resizeHeightProportionally

        public void resizeHeightProportionally(int newHeight,
                                               int resizeType)

        Resizes the width proportionally.

        Overrides:
        resizeHeightProportionally in class RasterCachedMultipageImage
        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();
        }
        

      • filter

        public void filter(Rectangle rectangle,
                           FilterOptionsBase options)

        Filters the specified rectangle.

        Overrides:
        filter in class RasterCachedMultipageImage
        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();
        }
        

      • resize

        public void resize(int newWidth,
                           int newHeight,
                           int resizeType)

        Resizes the image.

        Overrides:
        resize in class RasterCachedMultipageImage
        Parameters:
        newWidth - The new width.
        newHeight - The new height.
        resizeType - The resize type.
      • crop

        public void crop(int leftShift,
                         int rightShift,
                         int topShift,
                         int bottomShift)

        Crop image with shifts.

        Overrides:
        crop in class RasterCachedMultipageImage
        Parameters:
        leftShift - The left shift.
        rightShift - The right shift.
        topShift - The top shift.
        bottomShift - The bottom shift.
      • rotate

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

        !:RasterCahcedMultipageImage.Rotate image around the center.

        Overrides:
        rotate in class RasterCachedMultipageImage
        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 image contents are rotated.
        backgroundColor - Color of the background.
      • rotateFlip

        public void rotateFlip(int rotateFlipType)

        Rotates, flips, or rotates and flips the Active frame only.

        Overrides:
        rotateFlip in class RasterCachedMultipageImage
        Parameters:
        rotateFlipType - The rotate flip type.
        See Also:
        RotateFlipType