ILayerEffect.GetEffectBounds

ILayerEffect.GetEffectBounds method

Calculate and gets the bounds of effect pixels based on input layer pixels bounds.

public Rectangle GetEffectBounds(Rectangle layerBounds, int globalAngle)
ParameterTypeDescription
layerBoundsRectangleThe layer pixels bounds.
globalAngleInt32The global angle to calculate global light angle.

Return Value

The bounds of effect pixels based on input layer pixels bounds.

Examples

Demonstrates how to get a layer’s bounds with effects and export it with the correct size.

[C#]

string srcFile = "1958.psd";
string outputFile = "out_1958.png";

using (var psdImage = (PsdImage)Image.Load(srcFile, new PsdLoadOptions() { LoadEffectsResource = true }))
{
    var layer1 = psdImage.Layers[1];

    var layerBoudns = layer1.Bounds;
    foreach (var effect in layer1.BlendingOptions.Effects)
    {
        layerBoudns = Rectangle.Union(
            layerBoudns,
            effect.GetEffectBounds(layer1.Bounds, psdImage.GlobalAngle));
    }

    Rectangle boundsToExport = Rectangle.Empty; // The default value is to save only the layer with effects.
                                                // boundsToExport = psdImage.Bounds; // To save within the PsdImage bounds at the original layer location

    layer1.Save(
        outputFile,
        new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha },
        boundsToExport);

    using (var imgStream = new FileStream(outputFile, FileMode.Open))
    {
        var loadedLayer = new Layer(imgStream);
        if (loadedLayer.Size == layerBoudns.Size)
        {
            System.Console.WriteLine("The size is calculated correctly.");
        }
    }
}

See Also