Introduction
Aspose.PSD FOSS for .NET loads, inspects, and saves PSD and PSB documents through a small set of classes. This post looks at parts of the core API that the introductory post didn’t cover in depth: the Image/PsdImage inheritance relationship, the geometry value types used throughout the library, and how the library reports load and save errors.
What’s Included
Image and PsdImage
Image is the abstract base class and exposes Width, Height, Bounds, Load(), Save(), and Dispose(). PsdImage is the sealed, concrete implementation returned by Image.Load() for PSD/PSB input — casting the result to PsdImage exposes the rest of the document surface: ColorMode, Version, Layers, Compression, BitsPerChannel, and more.
using var image = (PsdImage)Image.Load(inputPath);
Console.WriteLine($"Bounds: {image.Bounds}"); // from the Image base class
Console.WriteLine($"ColorMode: {image.ColorMode}"); // PsdImage-specific
Geometry Value Types
Point, Size, Rectangle, and RectangleF are the value types used for bounds and coordinates across the API — Layer.Bounds and Image.Bounds are both Rectangle, and PsdImage.Size is a Size. Rectangle carries real geometry methods: Contains(), Intersect(), Union(), Inflate(), and FromLeftTopRightBottom(), among others.
Rectangle layerBounds = image.Layers[0].Bounds;
Rectangle imageBounds = image.Bounds;
bool fullyInside = imageBounds.Contains(layerBounds);
Rectangle overlap = Rectangle.Intersect(imageBounds, layerBounds);
Console.WriteLine($"Layer fits inside image: {fullyInside}, overlap: {overlap}");
Resource Blocks and Exceptions
PsdImage.ImageResources returns the parsed ResourceBlock[] array — each block exposes ID, DataSize, Name, and Signature. In this FOSS build, ImageResources, GlobalLayerResources, ActiveLayer, and HasTransparencyData can be read but not reassigned — each has a setter that throws NotSupportedException if called, so treat them as read-only even though they appear as properties.
Load and save errors surface as two dedicated exception types: PsdLoadException when a document can’t be parsed, and PsdSaveException when a document can’t be written back out.
try
{
using var image = (PsdImage)Image.Load(inputPath);
foreach (ResourceBlock resource in image.ImageResources)
{
Console.WriteLine($"Resource {resource.ID}: {resource.Name} ({resource.DataSize} bytes)");
}
}
catch (PsdLoadException ex)
{
Console.WriteLine($"Failed to load {inputPath}: {ex.Message}");
}
Quick Start
git clone https://github.com/aspose-psd-foss/Aspose.PSD-FOSS-for-.NET.git
cd Aspose.PSD-FOSS-for-.NET
dotnet buildusing Aspose.PSD.FileFormats.Psd;
try
{
using var image = (PsdImage)Image.Load("input.psd");
Console.WriteLine($"Bounds: {image.Bounds}, ColorMode: {image.ColorMode}");
Console.WriteLine($"ImageResources: {image.ImageResources.Length}");
}
catch (PsdLoadException ex)
{
Console.WriteLine($"Load failed: {ex.Message}");
}
Supported Formats
| Format | Extension | Read | Write |
|---|---|---|---|
| Photoshop Document | psd | ✓ | ✓ |
| Photoshop Large Document | psb | ✓ | ✓ |
Open Source & Licensing
Aspose.PSD FOSS for .NET is MIT licensed and may be used in commercial products without royalties, with no evaluation watermark or usage limit.
The package is at version 1.0.0 and requires only .NET 10.0 at runtime — it has no other third-party dependencies.