PixelMask Class

A set of pixels of an image: the region to fill of ImageProcessingExtensions.Inpaint, or the regions to keep and to remove of ImageProcessingExtensions.SeamCarve.

public sealed class PixelMask

Remarks

A new mask is empty. It holds one bit per pixel, in memory owned by the mask (not charged to an image). It is not thread-safe for writes.

Constructors

NameDescription
PixelMask(Size)Initializes a new instance of the PixelMask class, empty.
PixelMask(int, int)Initializes a new instance of the PixelMask class, empty.

PixelMask overloads

PixelMask(Size)

PixelMask.cs

Initializes a new instance of the PixelMask class, empty.

public PixelMask(Size size)
Parameters
size Size
The size. Must not be empty.
Exceptions
ArgumentOutOfRangeException
A side of size is not positive, or the mask would have more than Int32.MaxValue pixels.

PixelMask(int, int)

PixelMask.cs

Initializes a new instance of the PixelMask class, empty.

public PixelMask(int width, int height)
Parameters
width int
The width, in pixels. Must be positive.
height int
The height, in pixels. Must be positive.
Exceptions
ArgumentOutOfRangeException
width or height is not positive, or the mask would have more than Int32.MaxValue pixels.

Properties

NameDescription
CountGets the number of pixels of the mask.
HeightGets the height, in pixels.
SizeGets the size.
WidthGets the width, in pixels.

Gets the number of pixels of the mask.

public int Count { get; }

Property value

int

Gets the height, in pixels.

public int Height { get; }

Property value

int

Gets the size.

public Size Size { get; }

Property value

Size

Gets the width, in pixels.

public int Width { get; }

Property value

int

Indexers

NameDescription
this[int, int]Gets or sets whether a pixel belongs to the mask.

this[int, int]

PixelMask.cs

Gets or sets whether a pixel belongs to the mask.

public bool this[int x, int y] { get; set; }

Parameters

x int
The column, from 0 to Width - 1.
y int
The row, from 0 to Height - 1.

Property value

bool

Exceptions

ArgumentOutOfRangeException
x or y is outside the mask.

Methods

NameDescription
Clear()Removes every pixel from the mask.
Fill(Rectangle, bool)Adds the pixels of a rectangle to the mask, or removes them; the part of the rectangle outside the mask is ignored.
FromFrame(ImageFrame)Creates the mask of the light pixels of a frame: those whose Rec. 709 luma, premultiplied by their alpha, is at least half of the largest sample, such as the white strokes of a mask painted in black and white. For an PixelFormat.A8 frame, the pixels whose alpha is at least half.

Removes every pixel from the mask.

public void Clear()

Fill(Rectangle, bool)

PixelMask.cs

Adds the pixels of a rectangle to the mask, or removes them; the part of the rectangle outside the mask is ignored.

public void Fill(Rectangle rectangle, bool value = true)

Parameters

rectangle Rectangle
The rectangle.
value bool
true to add the pixels, false to remove them.

FromFrame(ImageFrame)

PixelMask.cs

Creates the mask of the light pixels of a frame: those whose Rec. 709 luma, premultiplied by their alpha, is at least half of the largest sample, such as the white strokes of a mask painted in black and white. For an PixelFormat.A8 frame, the pixels whose alpha is at least half.

public static PixelMask FromFrame(ImageFrame frame)

Parameters

frame ImageFrame
The frame.

Returns

PixelMask A mask of the size of the frame.

Exceptions

ArgumentNullException
frame is null.
UnsupportedImageFeatureException
The frame has CMYK pixels.
InvalidOperationException
A pixel lease is active.
ObjectDisposedException
The frame is no longer attached to a live image.