LinkedLayersManager.LinkLayers

LinkedLayersManager.LinkLayers method

Links the input layers and return LingGroupId.

public short LinkLayers(Layer[] layers)
ParameterTypeDescription
layersLayer[]The layers.

Return Value

The link group id.

Exceptions

exceptioncondition
ArgumentNullExceptionThe layers is null.
ArgumentExceptionThe number of layers must be greater than 1.
ArgumentExceptionThe container of each layer should be the same as the current PsdImage.

Examples

The following example demonstrates how you can manipulate Linked Layers in Aspose.PSD

[C#]

string sourceFile = "example.psd";
string outputFile = "psdnet11_output.psd";

// Load an existing image into an instance of PsdImage class
using (var psd = (PsdImage)Image.Load(sourceFile))
{
    Layer[] layers = psd.Layers;

    // link all layers in one linked group
    short layersLinkGroupId = psd.LinkedLayersManager.LinkLayers(layers);

    // gets id for one layer
    short linkGroupId = psd.LinkedLayersManager.GetLinkGroupId(layers[0]);
    if (layersLinkGroupId != linkGroupId)
    {
        throw new Exception("layersLinkGroupId and linkGroupId are not equal.");
    }

    // gets all linked layers by link group id.
    Layer[] linkedLayers = psd.LinkedLayersManager.GetLayersByLinkGroupId(linkGroupId);

    // unlink each layer from group
    foreach (var linkedLayer in linkedLayers)
    {
        psd.LinkedLayersManager.UnlinkLayer(linkedLayer);
    }

    // retrieves NULL for a link group ID that has no layers in the group.
    linkedLayers = psd.LinkedLayersManager.GetLayersByLinkGroupId(linkGroupId);
    if (linkedLayers != null)
    {
        throw new Exception("The linkedLayers field is not NULL.");
    }
    psd.Save(outputFile);
}

See Also