Core API

Core API

PsdImage is the entry point for loading, inspecting, and saving PSD/PSB documents. It extends the abstract Image base class, which declares Width, Height, Bounds, Load(), Save(), and Dispose().


Loading and Saving Documents

Image.Load() accepts a file path or a Stream and returns an Image; cast the result to PsdImage to access the rest of the document surface. PsdImage.Save() writes the document back out to a file path or stream.

using var image = (PsdImage)Image.Load(inputPath);
// ... inspect or edit ...
image.Save(outputPath);

Document Header Properties

PsdImage exposes the parsed header as typed properties: Width, Height, BitsPerChannel, ColorMode, Version, Compression, Size, and IsFlatten.

Console.WriteLine($"Width: {image.Width}, Height: {image.Height}");
Console.WriteLine($"ColorMode: {image.ColorMode}, Version: {image.Version}");
Console.WriteLine($"Compression: {image.Compression}, IsFlatten: {image.IsFlatten}");

Image Resources

PsdImage.ImageResources returns the parsed ResourceBlock[] array. In this FOSS build, ImageResources, GlobalLayerResources, ActiveLayer, and HasTransparencyData can be read but not reassigned — their setters throw NotSupportedException.

foreach (ResourceBlock resource in image.ImageResources)
{
    Console.WriteLine($"Resource {resource.ID}: {resource.Name} ({resource.DataSize} bytes)");
}

Tips and Best Practices

  • Always cast the result of Image.Load() to PsdImage to access PSD-specific members.
  • Wrap Dispose()-worthy objects in a using statement; PsdImage implements IDisposable.
  • Treat ImageResources, GlobalLayerResources, ActiveLayer, and HasTransparencyData as read-only even though they expose a setter.
  • Check image.Layers.Length before indexing into image.Layers — a flattened document may have zero layers.

Common Issues

IssueCauseFix
NotSupportedException when setting ImageResourcesThis property is read-only in the FOSS build despite having a setterRead the value; do not attempt to reassign it
Empty image.Layers array on a flattened documentIsFlatten is true and the document has no parsed layersCheck image.Layers.Length (or image.IsFlatten) before indexing into image.Layers

FAQ

Does loading a PSD document decode pixel data?

No. PsdImage.Load() parses the document header, layer metadata, and resources without decoding or rendering pixel data.

Can I convert a PSD file to another image format?

No. This library loads, inspects, and saves PSD/PSB documents only — it does not render pixel data or convert to other image formats.


API Reference Summary

Class/MethodDescription
Image.Load(string) / Image.Load(Stream)Loads a PSD or PSB document
PsdImage.Save(string) / PsdImage.Save(Stream)Saves the document
PsdImage.Width / Height / BitsPerChannel / ColorMode / Version / Compression / Size / IsFlattenDocument header properties
PsdImage.ImageResourcesParsed image resource blocks (read-only)

See Also