---
Product: psd
Platform: net
Page Type: docs
Canonical URL: https://docs.aspose.org/psd/net/developer-guide/layers
---

# Layers

How to read and edit layer metadata with the Layer class: geometry, visibility and compositing state, channel information, mask data, and blending ranges.

## Overview

`PsdImage.Layers` returns every parsed layer as a `Layer` array. Each `Layer` exposes its own geometry, visibility and compositing state, and metadata about its channels, mask, and blending ranges.

---

### Reading Layer Metadata

`Name`, `Bounds` (and the derived `Width`/`Height`/`Top`/`Left`/`Bottom`/`Right`), `IsVisible`, `Opacity`, `Clipping`, `BlendModeKey`, and `ChannelsCount` are all readable directly.

```csharp
foreach (Layer layer in image.Layers)
{
    Console.WriteLine($"{layer.Name}: {layer.Bounds}, " +
                       $"Visible={layer.IsVisible}, Opacity={layer.Opacity}, " +
                       $"BlendMode={layer.BlendModeKey}");
}
```

---

### Supported Metadata Edits

`Name`, `IsVisible`, `Opacity`, `Clipping`, `BlendModeKey`, and the four bounds edges (`Top`/`Left`/`Bottom`/`Right`) can be changed in place and written back with `PsdImage.Save()`.

```csharp
Layer layer = image.Layers[0];
layer.Name = $"{layer.Name} (edited)";
layer.IsVisible = !layer.IsVisible;
layer.Opacity = 128;
layer.BlendModeKey = BlendMode.Multiply;
image.Save(outputPath);
```

---

### Channel and Mask Metadata

`ChannelInformation`, `LayerMaskData`, and `LayerBlendingRangesData` are read-only in this FOSS build — their setters throw `NotSupportedException`.

```csharp
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}");
}
```

---

### Removing or Reordering Layers

`PsdImage.Layers` has a setter as well as a getter: assigning a filtered or reordered array replaces the document's layer collection. There is no public way to construct a brand-new `Layer` instance, so this only supports removing or reordering layers already present — not adding one from scratch.

```csharp
// Keep only visible layers
image.Layers = image.Layers.Where(layer => layer.IsVisible).ToArray();
image.Save(outputPath);
```

---

### Tips and Best Practices

- Index into `image.Layers` by position; the array order matches the document's own layer order.
- `BlendModeKey` accepts any `BlendMode` enum value — no validation is performed against the document's declared color mode.
- `ChannelInformation`, `LayerMaskData`, and `LayerBlendingRangesData` can be read but never reassigned.
- Call `PsdImage.Save()` once after all edits; each call writes the full document.

---

### Common Issues

| Issue | Cause | Fix |
|---|---|---|
| `NotSupportedException` when setting `ChannelInformation`, `LayerMaskData`, or `LayerBlendingRangesData` | These 3 properties are read-only in the FOSS build despite having a setter | Read the value; do not attempt to reassign it |
| `LayerMaskData` is `null` for a layer | Not every layer has a mask subsection | Check for `null` before use (`layer.LayerMaskData is { } mask`) |

---

### FAQ

#### Can I remove a layer?

Yes — reassign `image.Layers` to a filtered array. You cannot add a brand-new layer, since `Layer` has no public constructor; only existing parsed layers can be kept, removed, or reordered.

#### Can I change a layer's channel or mask data?

No. `ChannelInformation`, `LayerMaskData`, and `LayerBlendingRangesData` are read-only — only `Name`, `IsVisible`, `Opacity`, `Clipping`, `BlendModeKey`, and the bounds edges can be changed.

---

### API Reference Summary

| Class/Method | Description |
|---|---|
| `PsdImage.Layers` | Gets or sets the layer collection — settable for removal/reordering only |
| `Layer.Name` / `IsVisible` / `Opacity` / `Clipping` / `BlendModeKey` / `Top` / `Left` / `Bottom` / `Right` | Supported layer metadata edits |
| `Layer.Bounds` / `Width` / `Height` / `ChannelsCount` | Read-only layer geometry |
| `Layer.ChannelInformation` / `LayerMaskData` / `LayerBlendingRangesData` | Read-only channel/mask/blending metadata |

## See Also

- [Aspose.PSD — Enterprise Documentation](https://docs.aspose.com/psd/)