Table of Contents

Class SoftMask

Namespace
Egami.Drawing
Assembly
Egami.Drawing.dll

A mask made by drawing, as a PDF soft mask: Draw runs on a canvas of its own with the layer's transform and clip, and its alpha, or its luminosity over Backdrop, through the optional Transfer curve, multiplies the layer. A luminosity mask of a white shape on black shows the layer only inside the shape.

public sealed record SoftMask : IEquatable<SoftMask>
Inheritance
SoftMask
Implements
Inherited Members

Examples

using (RasterCanvas<Rgba8> canvas = raster.CreateCanvas())
{
    // A luminosity mask, as a PDF soft mask: white shows the photo, black hides it, a gradient fades it out to the right.
    RectF area = new(0, 0, photo.Width, photo.Height);
    SoftMask fade = new(mask => mask.FillRect(area, new LinearGradient(new Vector2(area.Width * 0.6f, 0), new Vector2(area.Width, 0), new RgbaF32(1, 1, 1, 1), new RgbaF32(0, 0, 0, 1))));
    canvas.SaveLayer(new LayerOptions { Mask = fade });
    canvas.DrawImage(photo, Vector2.Zero);
    canvas.Restore();
}

Constructors

SoftMask(Action<Canvas>, SoftMaskKind, RgbaF32?, Func<float, float>?)

Initializes a new instance of the SoftMask class.

public SoftMask(Action<Canvas> draw, SoftMaskKind kind = SoftMaskKind.Luminosity, RgbaF32? backdrop = null, Func<float, float>? transfer = null)

Parameters

draw Action<Canvas>

Draws the mask, in the layer's local coordinates.

kind SoftMaskKind

Whether alpha or luminosity becomes the mask.

backdrop RgbaF32?

The color a luminosity mask is drawn over; black when null, so undrawn areas mask everything out. An alpha mask ignores it.

transfer Func<float, float>

A curve from the mask value to the value used, both 0 to 1, as PDF's transfer function; null for none.

Exceptions

ArgumentNullException

draw is null.

ArgumentOutOfRangeException

kind is not defined.

Properties

Backdrop

Gets the color a luminosity mask is drawn over.

public RgbaF32 Backdrop { get; }

Property Value

RgbaF32

Draw

Gets the drawing that makes the mask.

public Action<Canvas> Draw { get; }

Property Value

Action<Canvas>

Kind

Gets whether alpha or luminosity becomes the mask.

public SoftMaskKind Kind { get; }

Property Value

SoftMaskKind

Transfer

Gets the curve applied to the mask value, or null for none.

public Func<float, float>? Transfer { get; }

Property Value

Func<float, float>