Table of Contents

Class PsdImage

Namespace
Egami.Formats.Psd
Assembly
Egami.dll

Reads what PSD and PSB hold besides the image Load gives: the layers, each with its pixels and mask.

public static class PsdImage
Inheritance
PsdImage
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}");
    }
}

Methods

ReadLayers(Stream, ReaderOptions?, EgamiContext?)

Reads every layer with its pixels from a stream; see ReadLayers(string, ReaderOptions?, EgamiContext?).

public static PsdDocument ReadLayers(Stream stream, ReaderOptions? options = null, EgamiContext? context = null)

Parameters

stream Stream

The file's data, from its start. It need not seek.

options ReaderOptions

The general options; the frame range is ignored.

context EgamiContext

The context, or null for Default.

Returns

PsdDocument

The document. The caller must dispose it.

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}");
    }
}

Exceptions

CorruptDataException

The data breaks the format's rules, including data of another format.

LimitExceededException

A layer or the layers together break a safety limit.

ReadLayers(string, ReaderOptions?, EgamiContext?)

Reads every layer with its pixels, for editors and for flattening: each in the natural pixel type Load would use, always with alpha (Rgba8, Rgba16 or RgbaF32 for RGB and Lab, GrayAlpha8 or GrayAlpha16 for gray, RgbaF32 for 32-bit gray), CMYK layers as an InkRaster. Load gives only the composite Photoshop stored.

public static PsdDocument ReadLayers(string path, ReaderOptions? options = null, EgamiContext? context = null)

Parameters

path string

The file.

options ReaderOptions

The general options; the frame range is ignored.

context EgamiContext

The context, or null for Default.

Returns

PsdDocument

The document. The caller must dispose it.

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}");
    }
}

Exceptions

CorruptDataException

The data breaks the format's rules, including data of another format.

LimitExceededException

A layer breaks MaxWidth, MaxHeight or MaxPixels, or the layers together break MaxTotalBytes.

ReadLayers<TPixel>(Stream, ReaderOptions?, EgamiContext?)

Reads every layer with its pixels converted to TPixel from a stream; see ReadLayers<TPixel>(string, ReaderOptions?, EgamiContext?).

public static PsdDocument ReadLayers<TPixel>(Stream stream, ReaderOptions? options = null, EgamiContext? context = null) where TPixel : unmanaged, IPixelType<TPixel>

Parameters

stream Stream

The file's data, from its start. It need not seek.

options ReaderOptions

The general options; the frame range is ignored.

context EgamiContext

The context, or null for Default.

Returns

PsdDocument

The document. The caller must dispose it.

Type Parameters

TPixel

The pixel type of the layers.

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}");
    }
}

Exceptions

CorruptDataException

The data breaks the format's rules, including data of another format.

LimitExceededException

A layer or the layers together break a safety limit.

ReadLayers<TPixel>(string, ReaderOptions?, EgamiContext?)

Reads every layer with its pixels converted to TPixel; see ReadLayers(string, ReaderOptions?, EgamiContext?). Every Pixels is a Raster<TPixel>; a CMYK layer keeps its Ink too.

public static PsdDocument ReadLayers<TPixel>(string path, ReaderOptions? options = null, EgamiContext? context = null) where TPixel : unmanaged, IPixelType<TPixel>

Parameters

path string

The file.

options ReaderOptions

The general options; the frame range is ignored.

context EgamiContext

The context, or null for Default.

Returns

PsdDocument

The document. The caller must dispose it.

Type Parameters

TPixel

The pixel type of the layers.

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}");
    }
}

Exceptions

CorruptDataException

The data breaks the format's rules, including data of another format.

LimitExceededException

A layer or the layers together break a safety limit.