Class SoftMask
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
drawAction<Canvas>Draws the mask, in the layer's local coordinates.
kindSoftMaskKindWhether alpha or luminosity becomes the mask.
backdropRgbaF32?The color a luminosity mask is drawn over; black when null, so undrawn areas mask everything out. An alpha mask ignores it.
transferFunc<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
drawis null.- ArgumentOutOfRangeException
kindis not defined.
Properties
Backdrop
Gets the color a luminosity mask is drawn over.
public RgbaF32 Backdrop { get; }
Property Value
Draw
Gets the drawing that makes the mask.
public Action<Canvas> Draw { get; }
Property Value
Kind
Gets whether alpha or luminosity becomes the mask.
public SoftMaskKind Kind { get; }
Property Value
Transfer
Gets the curve applied to the mask value, or null for none.
public Func<float, float>? Transfer { get; }