Table of Contents

Class PsdDocument

Namespace
Egami.Formats.Psd
Assembly
Egami.dll

A PSD or PSB file's layers with their pixels, from ReadLayers(string, ReaderOptions?, EgamiContext?).

public sealed class PsdDocument : IDisposable
Inheritance
PsdDocument
Implements
Inherited Members

Examples

// ReadLayers gives every layer with its pixels, bottom to top; a group comes after its contents.
using PsdDocument document = PsdImage.ReadLayers("layered.psd");
foreach (PsdLayerImage layer in document.Layers)
{
    if (layer.Pixels is Raster pixels)
    {
        // Each layer at its own size, in the natural type with alpha (Rgba8 here); X and Y place it on the canvas.
        pixels.Save($"layer-{layer.Index}.png");
        Console.WriteLine($"{layer.Info.Name}: {pixels.Width}×{pixels.Height} at ({layer.X}, {layer.Y}), in group {layer.ParentIndex}");
    }
}

Properties

BitsPerChannel

Gets the bits of each channel: 8, 16 or 32.

public int BitsPerChannel { get; }

Property Value

int

ColorMode

Gets the file's color mode.

public PsdColorMode ColorMode { get; }

Property Value

PsdColorMode

Context

Gets the context the layers were read with.

public EgamiContext Context { get; }

Property Value

EgamiContext

Height

Gets the canvas height in pixels.

public int Height { get; }

Property Value

int

Layers

Gets the layers and groups, bottom to top as the file lists them; a group comes after its contents, which name it in ParentIndex. The hidden records that mark where a group starts are left out.

public IReadOnlyList<PsdLayerImage> Layers { get; }

Property Value

IReadOnlyList<PsdLayerImage>

Metadata

Gets the file's metadata as Load gives it, with the PsdDetails and the warnings reading the layers raised.

public RasterMetadata Metadata { get; }

Property Value

RasterMetadata

Width

Gets the canvas width in pixels.

public int Width { get; }

Property Value

int

Methods

Dispose()

Disposes every layer's pixels and mask.

public void Dispose()

Flatten(PsdFlattenOptions?)

Composites the layers as Photoshop does, with each layer's Info as it is now, so a changed copy (a layer hidden, another opacity or blend mode) flattens differently: visibility, opacity, fill opacity (inside the formula of Photoshop's eight special modes), blend mode (all of Photoshop's), pixel and vector masks with their density and feather, clipping, pass-through and isolated groups, shallow and deep knockout, blending ranges, solid color fills and the levels, curves, hue/saturation, brightness/contrast and invert adjustments. Layer effects, other adjustments and gradient and pattern fills are left out with one warning a kind naming the layers. 8 and 16-bit documents blend their stored values (Lab its L*, a* and b*, turned into sRGB at the end), 32-bit ones linear light.

public Raster Flatten(PsdFlattenOptions? options = null)

Parameters

options PsdFlattenOptions

The options, or null for the defaults.

Returns

Raster

The flattened image at the canvas's size, in the type Load gives a file of this mode and depth: with alpha only when some pixel is not opaque. Its metadata is the document's, with the warnings of the flattening. The caller must dispose it.

Examples

// Flatten composites the layers as Photoshop does; change a layer's record first to flatten it differently.
using PsdDocument document = PsdImage.ReadLayers("layered.psd");
PsdLayerImage top = document.Layers[^1];
top.Info = top.Info with { IsVisible = false };
using Raster flat = document.Flatten();
foreach (EgamiDiagnostic warning in flat.Metadata.Warnings)
{
    // What the flattening left out, such as noise gradients, one warning a kind naming the layers.
    Console.WriteLine(warning.Message);
}

flat.Save("without-top.png");

Exceptions

UnsupportedFormatException

The document is bitmap, indexed, multichannel or 32-bit Lab, which Egami does not flatten.

LimitExceededException

The canvases the flattening needs break MaxTotalBytes.

ObjectDisposedException

The document has been disposed.

FlattenInk(PsdFlattenOptions?)

Composites a CMYK document's layers onto ink plates, as Flatten(PsdFlattenOptions?) does, with the ink blend math of Egami.Drawing's ink canvas: every blend mode on the inks' complements, the non-separable ones on cyan, magenta and yellow with black kept.

public InkRaster FlattenInk(PsdFlattenOptions? options = null)

Parameters

options PsdFlattenOptions

The options, or null for the defaults.

Returns

InkRaster

The flattened inks: the process inks of the file's CMYK profile (FOGRA39's when it has none), at the document's depth, premultiplied by the alpha plane. The caller must dispose it.

Examples

// Flatten composites the layers as Photoshop does; change a layer's record first to flatten it differently.
using PsdDocument document = PsdImage.ReadLayers("layered.psd");
PsdLayerImage top = document.Layers[^1];
top.Info = top.Info with { IsVisible = false };
using Raster flat = document.Flatten();
foreach (EgamiDiagnostic warning in flat.Metadata.Warnings)
{
    // What the flattening left out, such as noise gradients, one warning a kind naming the layers.
    Console.WriteLine(warning.Message);
}

flat.Save("without-top.png");

Exceptions

UnsupportedFormatException

The document is not CMYK.

LimitExceededException

The canvases the flattening needs break MaxTotalBytes.

ObjectDisposedException

The document has been disposed.