Class PsdImage

PsdImage class

Defines the PsdImage class that provides the ability to load, edit, save PSD files as well as update properties, add watermarks, perform graphics operations or convert one file format to another. Aspose.PSD supports import as a layer and export to the following formats: Png, Jpeg, Jpeg2000, Gif, Bmp, Tiff, Psd, Psb along with export to Pdf with selectable text

public sealed class PsdImage : RasterCachedImage

Constructors

NameDescription
PsdImage(RasterImage)Initializes a new instance of the PsdImage class from existing raster image (not psd image) with RGB color mode with 4 channels 8 bit/channel and no compression.
PsdImage(Stream)Initializes a new instance of the 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.
PsdImage(string)Initializes a new instance of the 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.
PsdImage(int, int)Initializes a new instance of the PsdImage class with specified width and height. Used to initialize empty psd image.
PsdImage(RasterImage, ColorModes, short, short, int, CompressionMethod)Initializes a new instance of the PsdImage class from existing raster image (not psd image) with constructor parameters.
PsdImage(Stream, ColorModes, short, short, int, CompressionMethod)Initializes a new instance of the PsdImage class from specified path from raster image (not psd image in stream) with constructor parameters.
PsdImage(string, ColorModes, short, short, int, CompressionMethod)Initializes a new instance of the PsdImage class from specified path from raster image (not psd image in path) with constructor parameters.
PsdImage(int, int, IColorPalette, ColorModes, short, short, int, CompressionMethod)Initializes a new instance of the 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.

Properties

NameDescription
ActiveLayer { get; set; }Gets or sets the active layer.
AutoAdjustPalette { get; set; }Gets or sets a value indicating whether automatic adjust palette.
virtual BackgroundColor { get; set; }Gets or sets a value for the background color.
BitsPerChannel { get; }Gets the bits per channel.
override BitsPerPixel { get; }Gets the image bits per pixel count.
Bounds { get; }Gets the image bounds.
BufferSizeHint { get; set; }Gets or sets the buffer size hint which is defined max allowed size for all internal buffers.
ChannelsCount { get; }Gets the PSD channels count.
CmykColorProfile { get; set; }Gets or sets the CMYK color profile for CMYK PSD images. Must be in pair with RgbColorProfile for correct color conversion.
ColorMode { get; set; }Gets or sets the color mode.
Compression { get; }Gets the compression method.
Container { get; }Gets the Image container.
DataStreamContainer { get; }Gets the object’s data stream.
Disposed { get; }Gets a value indicating whether this instance is disposed.
override FileFormat { get; }Gets a value of file format
GlobalAngle { get; set; }Gets or sets the global angle.
GlobalLayerMaskInfo { get; }Gets the global layer mask info.
GlobalLayerResources { get; set; }Gets or sets the global layer resources.
GrayColorProfile { get; set; }Gets or sets the GRAY (monochrome) color profile for Grayscale PSD images.
override HasAlpha { get; }Gets or sets the vertical resolution, in pixels per inch, of this RasterImage.
virtual HasBackgroundColor { get; set; }Gets or sets a value indicating whether image has background color.
HasTransparencyData { get; set; }Gets or sets a value indicating whether first alpha channel contains the transparency data for the merged result when specifying layers data.
virtual HasTransparentColor { get; set; }Gets a value indicating whether image has transparent color.
override Height { get; }Gets the image height.
override HorizontalResolution { get; set; }Gets or sets the horizontal resolution, in pixels per inch, of this PsdImage.
virtual ImageOpacity { get; }Gets opacity of this image.
ImageResources { get; set; }Gets or sets the PSD image resources.
InterruptMonitor { get; set; }Gets or sets the interrupt monitor.
override IsCached { get; }Gets a value indicating whether image data is cached currently.
IsFlatten { get; }Gets a value indicating whether psd image is flattened.
IsRawDataAvailable { get; }Gets a value indicating whether raw data loading is available.
Layers { get; set; }Gets or sets the PSD layers.
LinkedLayersManager { get; }Gets the linked layers manager.
Palette { get; set; }Gets or sets the color palette. The color palette is not used when pixels are represented directly.
virtual PremultiplyComponents { get; set; }Gets or sets a value indicating whether the image components must be premultiplied.
RawCustomColorConverter { get; set; }Gets or sets the custom color converter
override RawDataFormat { get; }Gets the raw data format.
RawDataSettings { get; }Gets the current raw data settings. Note when using these settings the data loads without conversion.
RawFallbackIndex { get; set; }Gets or sets the fallback index to use when palette index is out of bounds
RawIndexedColorConverter { get; set; }Gets or sets the indexed color converter
virtual RawLineSize { get; }Gets the raw line size in bytes.
RgbColorProfile { get; set; }Gets or sets the RGB color profile for CMYK PSD images. Must be in pair with CmykColorProfile for correct color conversion.
Size { get; }Gets the image size.
SmartObjectProvider { get; }Gets the smart object provider.
Timeline { get; }Gets the Timeline of this PsdImage.
virtual TransparentColor { get; set; }Gets the image transparent color.
virtual UpdateXmpData { get; set; }Gets or sets a value indicating whether to update the XMP metadata.
virtual UsePalette { get; }Gets a value indicating whether the image palette is used.
virtual UseRawData { get; set; }Gets or sets a value indicating whether to use raw data loading when the raw data loading is available.
Version { get; set; }Gets or sets the version.
override VerticalResolution { get; set; }Gets or sets the vertical resolution, in pixels per inch, of this PsdImage.
override Width { get; }Gets the image width.
override XmpData { get; set; }Gets or sets the XMP metadata.

Methods

NameDescription
AddBlackWhiteAdjustmentLayer()Adds the black white adjustment layer.
AddBrightnessContrastAdjustmentLayer(int, int)Adds the brightness/contrast adjustment layer.
AddChannelMixerAdjustmentLayer()Adds the channel mixer adjustment layer with default parameters
AddColorBalanceAdjustmentLayer()Adds the color balance adjustment layer.
AddCurvesAdjustmentLayer()Adds the Curves Adjustment layer.
AddExposureAdjustmentLayer(float, float, float)Adds the exposure adjustment layer.
AddGradientMapAdjustmentLayer()Adds GradientMap Adjustment layer.
AddHueSaturationAdjustmentLayer()Adds the hue/saturation adjustment layer.
AddInvertAdjustmentLayer()Adds an invert adjustment layer.
AddLayer(Layer)Adds the layer.
AddLayerGroup(string, int, bool)Adds the layer group.
AddLevelsAdjustmentLayer()Adds the Levels adjustment layer.
AddPhotoFilterLayer(Color)Adds the PhotoFilter layer.
AddPosterizeAdjustmentLayer()Adds Posterize Adjustment layer.
AddRegularLayer()Adds a new regular layer.
AddSelectiveColorAdjustmentLayer()Adds the selective color adjustment layer.
AddShapeLayer()Add empty Shape layer. Without paths. They should be added to shape layer before save.
AddTextLayer(string, Rectangle)Adds a new Text layer.
AddThresholdAdjustmentLayer()Adds the Threshold adjustment layer.
AddVibranceAdjustmentLayer()Adds the Vibrance adjustment layer.
override AdjustBrightness(int)Adjust of a brightness for image.
override AdjustContrast(float)Image contrasting
override AdjustGamma(float)Gamma-correction of an image.
override AdjustGamma(float, float, float)Gamma-correction of an image.
override BinarizeBradley(double)Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding
override BinarizeBradley(double, int)Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding
override BinarizeFixed(byte)Binarization of an image with predefined threshold
override BinarizeOtsu()Binarization of an image with Otsu thresholding
override CacheData()Caches the data and ensures no additional data loading will be performed from the underlying DataStreamContainer.
CanSave(ImageOptionsBase)Determines whether image can be saved to the specified file format represented by the passed save options.
Convert(PsdOptions)Converts this image format to the one specified in options.
override Crop(Rectangle)Cropping the image.
virtual Crop(int, int, int, int)Crop image with shifts.
Dispose()Disposes the current instance.
Dither(DitheringMethod, int)Performs dithering on the current image.
override Dither(DitheringMethod, int, IColorPalette)Performs dithering on the current image.
override Filter(Rectangle, FilterOptionsBase)Filters the specified rectangle.
FlattenImage()Flattens all layers.
GetArgb32Pixel(int, int)Gets an image 32-bit ARGB pixel.
GetDefaultArgb32Pixels(Rectangle)Gets the default 32-bit ARGB pixels array.
virtual GetDefaultOptions(object[])Gets the default options.
GetDefaultPixels(Rectangle, IPartialArgb32PixelLoader)Gets the default pixels array using partial pixel loader.
GetDefaultRawData(Rectangle, RawDataSettings)Gets the default raw data array.
GetDefaultRawData(Rectangle, IPartialRawDataLoader, RawDataSettings)Gets the default raw data array using partial pixel loader.
virtual GetModifyDate(bool)Gets the date and time the resource image was last modified.
virtual GetOriginalOptions()Gets the options based on the original file settings. This can be helpful to keep bit-depth and other parameters of the original image unchanged. For example, if we load a black-white PNG image with 1 bit per pixel and then save it using the Save method, the output PNG image with 8-bit per pixel will be produced. To avoid it and save PNG image with 1-bit per pixel, use this method to get corresponding saving options and pass them to the Save method as the second parameter.
GetPixel(int, int)Gets an image pixel.
GetSkewAngle()Gets the skew angle. This method is applicable to scanned text documents, to determine the skew angle when scanning.
override Grayscale()Transformation of an image to its grayscale representation
LoadArgb32Pixels(Rectangle)Loads 32-bit ARGB pixels.
LoadArgb64Pixels(Rectangle)Loads 64-bit ARGB pixels.
LoadCmyk32Pixels(Rectangle)Loads pixels in CMYK format.
LoadCmykPixels(Rectangle)Loads pixels in CMYK format. This method is deprecated. Please use more effective the LoadCmyk32Pixels method.
LoadPartialArgb32Pixels(Rectangle, IPartialArgb32PixelLoader)Loads 32-bit ARGB pixels partially by packs.
LoadPartialPixels(Rectangle, IPartialPixelLoader)Loads pixels partially by packs.
LoadPixels(Rectangle)Loads pixels.
LoadRawData(Rectangle, RawDataSettings, IPartialRawDataLoader)Loads raw data.
LoadRawData(Rectangle, Rectangle, RawDataSettings, IPartialRawDataLoader)Loads raw data.
MergeLayers(Layer, Layer)Merges the layers.
NormalizeAngle()Normalizes the angle. This method is applicable to scanned text documents to get rid of the skewed scan. This method uses GetSkewAngle and Rotate methods.
virtual NormalizeAngle(bool, Color)Normalizes the angle. This method is applicable to scanned text documents to get rid of the skewed scan. This method uses GetSkewAngle and Rotate methods.
ReadArgb32ScanLine(int)Reads the whole scan line by the specified scan line index.
ReadScanLine(int)Reads the whole scan line by the specified scan line index.
ReplaceColor(Color, byte, Color)Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.
override ReplaceColor(int, byte, int)Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.
ReplaceNonTransparentColors(Color)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.
override ReplaceNonTransparentColors(int)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.
Resize(int, int)Resizes the image. The default NearestNeighbourResample is used.
override Resize(int, int, ImageResizeSettings)Resizes the image.
override Resize(int, int, ResizeType)Resizes the image.
ResizeHeightProportionally(int)Resizes the height proportionally.
override ResizeHeightProportionally(int, ImageResizeSettings)Resizes the height proportionally.
override ResizeHeightProportionally(int, ResizeType)Resizes the height proportionally.
ResizeWidthProportionally(int)Resizes the width proportionally. The default NearestNeighbourResample is used.
override ResizeWidthProportionally(int, ImageResizeSettings)Resizes the width proportionally.
override ResizeWidthProportionally(int, ResizeType)Resizes the width proportionally.
override Rotate(float)Rotate image around the center.
override Rotate(float, bool, Color)Rotate image around the center.
override RotateFlip(RotateFlipType)Rotates, flips, or rotates and flips the image.
Save()Saves the image data to the underlying stream.
virtual Save(Stream)Saves the object’s data to the specified stream.
Save(string)Saves the object’s data to the specified file location.
Save(Stream, ImageOptionsBase)Saves the image’s data to the specified stream in the specified file format according to save options.
virtual Save(string, bool)Saves the object’s data to the specified file location.
virtual Save(string, ImageOptionsBase)Saves the object’s data to the specified file location in the specified file format according to save options.
override Save(Stream, ImageOptionsBase, Rectangle)Saves the image’s data to the specified stream in the specified file format according to save options.
virtual Save(string, ImageOptionsBase, Rectangle)Saves the object’s data to the specified file location in the specified file format according to save options.
SaveArgb32Pixels(Rectangle, int[])Saves the 32-bit ARGB pixels.
SaveCmyk32Pixels(Rectangle, int[])Saves the pixels.
SaveCmykPixels(Rectangle, CmykColor[])Saves the pixels. This method is deprecated. Please use more effective the SaveCmyk32Pixels method.
SavePixels(Rectangle, Color[])Saves the pixels.
SaveRawData(byte[], int, Rectangle, RawDataSettings)Saves the raw data.
SetArgb32Pixel(int, int, int)Sets an image 32-bit ARGB pixel for the specified position.
override SetPalette(IColorPalette, bool)Sets the image palette.
SetPixel(int, int, Color)Sets an image pixel for the specified position.
override SetResolution(double, double)Sets the resolution for this PsdImage.
virtual ToBitmap()Converts raster image to the bitmap.
WriteArgb32ScanLine(int, int[])Writes the whole scan line to the specified scan line index.
WriteScanLine(int, Color[])Writes the whole scan line to the specified scan line index.

Fields

NameDescription
const DefaultVersionThe default PSD version.

Examples

The following code demonstrates ability to rotate the image by specific angle value.

[C#]

string sourceFileName = "TheHat.psd";
var pngOptions = new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha };

// Whole image rotating
using (PsdImage image = (PsdImage)Image.Load(sourceFileName))
{
    for (int i = 0; i < 4; i++)
    {
        int angle = i * 45;
        image.Rotate(angle);

        string outFileName = "TheHatRotated" + angle + ".png";

        image.Save(outFileName, pngOptions);
    }
}

// Layer rotating
using (PsdImage image = (PsdImage)Image.Load(sourceFileName))
{
    for (int i = 0; i < 4; i++)
    {
        int angle = i * 45;
        image.Layers[1].Rotate(angle);

        string outFileName = "TheHatLayerRotated" + angle + ".png";

        image.Save(outFileName, pngOptions);
    }
}

See Also