How to Work with the Aspose.PSD FOSS Core API in .NET
View as Markdown

How to Work with the Aspose.PSD FOSS Core API in .NET

Aspose.PSD FOSS for .NET loads and inspects PSD/PSB document structure through PsdImage, a subclass of Image. This article covers loading a document, reading its header and image resources, and saving it back to disk.

Step-by-Step Guide

Step 1: Install the Package

dotnet add package Aspose.PSD.FOSS

Step 2: Import Required Classes

using Aspose.PSD.FileFormats.Psd;

Step 3: Load a PSD/PSB Document

PsdImage.Load opens a document from a file path or a stream:

using var image = PsdImage.Load("input.psd");

Step 4: Inspect the Document Header

PsdImage exposes header fields read from the parsed document: Width, Height, BitsPerChannel, ColorMode (a ColorModes value), and Compression (a CompressionMethod value):

Console.WriteLine($"{image.Width}x{image.Height}, {image.BitsPerChannel} bpc");
Console.WriteLine($"Color mode: {image.ColorMode}");   // e.g. ColorModes.Rgb
Console.WriteLine($"Compression: {image.Compression}"); // e.g. CompressionMethod.RLE
Console.WriteLine($"Flattened: {image.IsFlatten}");

ColorModes values include Bitmap, Grayscale, Indexed, Rgb, and Cmyk, among others (Multichannel, Duotone, Lab). CompressionMethod values are Raw, RLE, ZipWithoutPrediction, and a ZIP-with-prediction variant.


Step 5: Read Image Resource Blocks

ImageResources returns the document’s parsed ResourceBlock entries. Each block exposes ID, Name, and Size:

foreach (var resource in image.ImageResources)
{
    Console.WriteLine($"Resource {resource.ID} \"{resource.Name}\" - {resource.Size} bytes");
}

ImageResources is read-only in this FOSS build — assigning to it throws NotSupportedException (see Known Limitations in the FAQ).


Step 6: Save the Document

image.Save("output.psd");

Common Issues and Fixes

PsdLoadException when loading a file. The input is not a valid PSD/PSB document, or its header failed validation. Confirm the file is a genuine PSD/PSB file before loading.

NotSupportedException when setting ImageResources or GlobalLayerResources. These setters are not supported in this FOSS build. Treat ImageResources as read-only.

ColorMode or Compression prints as a numeric value instead of a name. Cast the property to its enum type explicitly, or use .ToString(), to get the readable name (ColorModes.Rgb, not 3).

Frequently Asked Questions

Can I load a PSD file from a stream instead of a file path?

Yes — PsdImage.Load has an overload that accepts a Stream.

Does ImageResources include layer data?

No. ImageResources holds document-level resource blocks (parsed from the PSD image resources section). Layer-level data is read through PsdImage.Layers — see Working with Layers.

Is PsdImage.Version the PSD file format version?

No. PsdImage.Version reports an internal Aspose.PSD-compatible API version number (currently 6) — it is unrelated to whether the loaded file is PSD or PSB.

See Also

 English