Packages

 

com.aspose.imaging.fileformats.psd

Class PsdImage

    • 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.
      • 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.
      • 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.
      • 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.
      • 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.
      • 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.
      • 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.
    • Method Detail

      • getFileFormat

        public long getFileFormat()

        Gets a value of file format

        Overrides:
        getFileFormat in class Image
      • hasAlpha

        public boolean hasAlpha()

        Gets a flag indicating whether this instance has alpha channel.

        Overrides:
        hasAlpha in class RasterImage
        Returns:
        a flag indicating whether this instance has alpha channel.
      • 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.

      • 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.

      • 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.
      • 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.

      • addRegularLayer

        public final Layer addRegularLayer()

        Adds a new regular layer.

        Returns:
        Created regular layer.
      • 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.
      • 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.
      • 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.
      • 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.
      • 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.