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()toPsdImageto access PSD-specific members. - Wrap
Dispose()-worthy objects in ausingstatement;PsdImageimplementsIDisposable. - Treat
ImageResources,GlobalLayerResources,ActiveLayer, andHasTransparencyDataas read-only even though they expose a setter. - Check
image.Layers.Lengthbefore indexing intoimage.Layers— a flattened document may have zero layers.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
NotSupportedException when setting ImageResources | This property is read-only in the FOSS build despite having a setter | Read the value; do not attempt to reassign it |
Empty image.Layers array on a flattened document | IsFlatten is true and the document has no parsed layers | Check 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/Method | Description |
|---|---|
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 / IsFlatten | Document header properties |
PsdImage.ImageResources | Parsed image resource blocks (read-only) |