Class ImageGrayscaleMask

Class ImageGrayscaleMask

Namespace: Aspose.Imaging.MagicWand.ImageMasks
Assembly: Aspose.Imaging.dll (25.2.0)

Describes a grayscale image mask.

public class ImageGrayscaleMask : IImageMask, ICloneable

Inheritance

objectImageGrayscaleMask

Implements

IImageMask, ICloneable

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Examples

The example shows how to select a complicated area of an image using Magic Wand tool and the ability to interact with masks (invert, union, substract).```csharp [C#]

                                                                                                                                                              var imageFilePath = "input.png"; 
                                                                                                                                                              using (RasterImage image = (RasterImage)Image.Load(inputFilePath))
                                                                                                                                                              {
                                                                                                                                                                  // Create a new mask using magic wand tool based on tone and color of pixel (845, 128)
                                                                                                                                                                  MagicWandTool.Select(image, new MagicWandSettings(845, 128))
                                                                                                                                                                      // Union the existing mask with the specified one created by magic wand tool
                                                                                                                                                                      .Union(new MagicWandSettings(416, 387))
                                                                                                                                                                      // Invert the existing mask
                                                                                                                                                                      .Invert()
                                                                                                                                                                      // Subtract the specified mask created by magic wand tool with specified threshold from the existing one 
                                                                                                                                                                      .Subtract(new MagicWandSettings(1482, 346) { Threshold = 69 })
                                                                                                                                                                      // Subtract four specified rectangle masks from the existing mask one by one
                                                                                                                                                                      .Subtract(new RectangleMask(0, 0, 800, 150))
                                                                                                                                                                      .Subtract(new RectangleMask(0, 380, 600, 220))
                                                                                                                                                                      .Subtract(new RectangleMask(930, 520, 110, 40))
                                                                                                                                                                      .Subtract(new RectangleMask(1370, 400, 120, 200))
                                                                                                                                                                      // Feather mask with specified settings
                                                                                                                                                                      .GetFeathered(new FeatheringSettings() { Size = 3 })
                                                                                                                                                                      // Apply mask to the image
                                                                                                                                                                      .Apply();

                                                                                                                                                                  // Save image
                                                                                                                                                                  image.Save(outputFilePath);
                                                                                                                                                              }

## Constructors

### <a id="Aspose_Imaging_MagicWand_ImageMasks_ImageGrayscaleMask__ctor_System_Int32_System_Int32_"></a> ImageGrayscaleMask\(int, int\)

Initializes a new instance of the Aspose.Imaging.MagicWand.ImageMasks.ImageGrayscaleMask class with the specified width and height.

```csharp
public ImageGrayscaleMask(int width, int height)

Parameters

width int

Width of the mask.

height int

Height of the mask.

ImageGrayscaleMask(RasterImage)

Initializes a new instance of the Aspose.Imaging.MagicWand.ImageMasks.ImageGrayscaleMask class with the size of the specified existing Aspose.Imaging.RasterImage. Specified Aspose.Imaging.RasterImage will be stored as source image.

public ImageGrayscaleMask(RasterImage image)

Parameters

image RasterImage

Source image.

Properties

Bounds

Gets the bounds, in pixels, of this mask.

public Rectangle Bounds { get; }

Property Value

Rectangle

Height

Gets the height, in pixels, of this mask.

public int Height { get; }

Property Value

int

SelectionBounds

Gets the bounds of the selected part of the mask, in pixels.

public Rectangle SelectionBounds { get; }

Property Value

Rectangle

Source

Gets the source image used to create this mask, if exists.

public RasterImage Source { get; }

Property Value

RasterImage

Width

Gets the width, in pixels, of this mask.

public int Width { get; }

Property Value

int

this[int, int]

Gets or sets the opacity of the specified pixel.

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

Property Value

byte

Methods

Apply()

Applies current mask to the Aspose.Imaging.RasterImage source, if exists.

public void Apply()

Exceptions

NullReferenceException

Thrown when the source image is not defined.

ApplyTo(RasterImage)

Applies current mask to the specified Aspose.Imaging.RasterImage.

public void ApplyTo(RasterImage image)

Parameters

image RasterImage

Image to apply mask to.

Exceptions

ArgumentNullException

Thrown when the image is not defined.

Clone()

Creates a new object that is a copy of the current instance.

public object Clone()

Returns

object

A new object that is a copy of this instance.

Crop(Size)

Crops mask with the specified size.

public ImageGrayscaleMask Crop(Size size)

Parameters

size Size

The specified size.

Returns

ImageGrayscaleMask

An cropped Aspose.Imaging.MagicWand.ImageMasks.ImageGrayscaleMask.

Crop(int, int)

Crops mask with the specified width and height.

public ImageGrayscaleMask Crop(int width, int height)

Parameters

width int

The specified width.

height int

The specified height.

Returns

ImageGrayscaleMask

An cropped Aspose.Imaging.MagicWand.ImageMasks.ImageGrayscaleMask.

Crop(Rectangle)

Crops mask with the specified rectangle.

public ImageGrayscaleMask Crop(Rectangle rectangle)

Parameters

rectangle Rectangle

The specified rectangle.

Returns

ImageGrayscaleMask

A cropped Aspose.Imaging.MagicWand.ImageMasks.ImageGrayscaleMask.

ExclusiveDisjunction(ImageGrayscaleMask)

Gets the exclusive disjunction of current mask with provided.

public ImageGrayscaleMask ExclusiveDisjunction(ImageGrayscaleMask mask)

Parameters

mask ImageGrayscaleMask

Provided mask

Returns

ImageGrayscaleMask

New Aspose.Imaging.MagicWand.ImageMasks.ImageGrayscaleMask.

GetByteOpacity(int, int)

Gets the opacity of the specified pixel with byte precision.

public byte GetByteOpacity(int x, int y)

Parameters

x int

The x-coordinate of the pixel.

y int

The y-coordinate of the pixel.

Returns

byte

Byte value, representing the opacity of the specified pixel.

Intersect(ImageGrayscaleMask)

Gets the intersection of current mask with provided.

public ImageGrayscaleMask Intersect(ImageGrayscaleMask mask)

Parameters

mask ImageGrayscaleMask

Provided mask

Returns

ImageGrayscaleMask

New Aspose.Imaging.MagicWand.ImageMasks.ImageGrayscaleMask.

Invert()

Gets the inversion of the current mask.

public ImageGrayscaleMask Invert()

Returns

ImageGrayscaleMask

New Aspose.Imaging.MagicWand.ImageMasks.ImageGrayscaleMask.

IsOpaque(int, int)

Checks if the specified pixel is opaque.

public bool IsOpaque(int x, int y)

Parameters

x int

The x-coordinate of the pixel.

y int

The y-coordinate of the pixel.

Returns

bool

true if the specified pixel is opaque; otherwise, false.

IsTransparent(int, int)

Checks if the specified pixel is transparent.

public bool IsTransparent(int x, int y)

Parameters

x int

The x-coordinate of the pixel.

y int

The y-coordinate of the pixel.

Returns

bool

true if the specified pixel is transparent; otherwise, false.

Subtract(ImageGrayscaleMask)

Gets the subtraction of the provided mask from current.

public ImageGrayscaleMask Subtract(ImageGrayscaleMask mask)

Parameters

mask ImageGrayscaleMask

Provided mask

Returns

ImageGrayscaleMask

New Aspose.Imaging.MagicWand.ImageMasks.ImageGrayscaleMask.

Union(ImageGrayscaleMask)

Union of two masks.

public ImageGrayscaleMask Union(ImageGrayscaleMask mask)

Parameters

mask ImageGrayscaleMask

Provided mask

Returns

ImageGrayscaleMask

New Aspose.Imaging.MagicWand.ImageMasks.ImageGrayscaleMask.

Operators

operator +(ImageGrayscaleMask, ImageGrayscaleMask)

Union of two masks.

public static ImageGrayscaleMask operator +(ImageGrayscaleMask a, ImageGrayscaleMask b)

Parameters

a ImageGrayscaleMask

The first mask.

b ImageGrayscaleMask

The second mask.

Returns

ImageGrayscaleMask

New Aspose.Imaging.MagicWand.ImageMasks.ImageGrayscaleMask.

operator ^(ImageGrayscaleMask, ImageGrayscaleMask)

Exclusive disjunction of two masks.

public static ImageGrayscaleMask operator ^(ImageGrayscaleMask a, ImageGrayscaleMask b)

Parameters

a ImageGrayscaleMask

The first mask.

b ImageGrayscaleMask

The second mask.

Returns

ImageGrayscaleMask

New Aspose.Imaging.MagicWand.ImageMasks.ImageGrayscaleMask.

operator !(ImageGrayscaleMask)

Inverts mask.

public static ImageGrayscaleMask operator !(ImageGrayscaleMask a)

Parameters

a ImageGrayscaleMask

The mask to be inverted.

Returns

ImageGrayscaleMask

New Aspose.Imaging.MagicWand.ImageMasks.ImageGrayscaleMask.

operator *(ImageGrayscaleMask, ImageGrayscaleMask)

Intersection of two masks.

public static ImageGrayscaleMask operator *(ImageGrayscaleMask a, ImageGrayscaleMask b)

Parameters

a ImageGrayscaleMask

The first mask.

b ImageGrayscaleMask

The second mask.

Returns

ImageGrayscaleMask

New Aspose.Imaging.MagicWand.ImageMasks.ImageGrayscaleMask.

operator -(ImageGrayscaleMask, ImageGrayscaleMask)

Subtract second mask from first.

public static ImageGrayscaleMask operator -(ImageGrayscaleMask a, ImageGrayscaleMask b)

Parameters

a ImageGrayscaleMask

The first mask.

b ImageGrayscaleMask

The second mask.

Returns

ImageGrayscaleMask

New Aspose.Imaging.MagicWand.ImageMasks.ImageGrayscaleMask.