Introduction
PsdImage.Layers returns every layer in a PSD or PSB document as a Layer array. This post looks specifically at what a Layer exposes: its geometry and visual state, the blend mode and mask flag enumerations, and the metadata classes that describe a layer’s channels, mask, and blending ranges.
What’s Included
The Layer Class
Each Layer carries a Pascal name (Name), a bounding Rectangle (Bounds, with derived Width/Height/Top/Left/Bottom/Right), visibility and compositing state (IsVisible, Opacity, Clipping, BlendModeKey), and a channel count (ChannelsCount). Name, IsVisible, Opacity, Clipping, BlendModeKey, and the four bounds edges can all be changed and written back with PsdImage.Save().
using var image = (PsdImage)Image.Load(inputPath);
foreach (Layer layer in image.Layers)
{
Console.WriteLine($"{layer.Name}: {layer.Bounds}, " +
$"Visible={layer.IsVisible}, Opacity={layer.Opacity}, " +
$"BlendMode={layer.BlendModeKey}");
}
Blend Modes and Mask Flags
BlendModeKey is a BlendMode enum value — the library defines all 29 standard PSD blend modes (Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity, and others). A separate LayerMaskFlags enum (None, RelativeToLayer, Disabled, InvertedWhenBlending, UserMaskFromRenderingOtherData, UserOrVectorMasksHaveParameters) describes mask-rendering behavior where a layer has one.
Channel and Mask Metadata
Layer.ChannelInformation returns a ChannelInformation[] describing each channel’s ID, compression method, and byte length. Layer.LayerMaskData (an abstract LayerMaskData, concretely a LayerMaskDataShort when present) describes a layer mask’s bounds and flags; Layer.LayerBlendingRangesData exposes the composite and per-channel blend ranges. All three of these properties are read-only in this FOSS build — their setters throw NotSupportedException if called, even though they appear as regular get/set properties.
Layer layer = image.Layers[0];
foreach (ChannelInformation channel in layer.ChannelInformation)
{
Console.WriteLine($"Channel {channel.ChannelID}: {channel.CompressionMethod}, {channel.Length} bytes");
}
if (layer.LayerMaskData is { } mask)
{
Console.WriteLine($"Mask bounds: {mask.MaskRectangle}, flags: {mask.Flags}");
}
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;
using Aspose.PSD.FileFormats.Psd.Layers;
using System.Linq;
using var image = (PsdImage)Image.Load("input.psd");
var visibleLayers = image.Layers.Where(layer => layer.IsVisible);
foreach (Layer layer in visibleLayers)
{
Console.WriteLine($"{layer.Name}: Opacity={layer.Opacity}, BlendMode={layer.BlendModeKey}");
}
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.