Class RectangleMask
Namespace: Aspose.Imaging.MagicWand.ImageMasks
Assembly: Aspose.Imaging.dll (25.2.0)
Describes a rectangle mask.
public class RectangleMask : ImageMask, IImageMask, ICloneable
Inheritance
object ← ImageMask ← RectangleMask
Implements
Inherited Members
ImageMask.Inflate(int), ImageMask.Crop(Size), ImageMask.Crop(int, int), ImageMask.Crop(Rectangle), ImageMask.IsOpaque(int, int), ImageMask.IsTransparent(int, int), ImageMask.GetByteOpacity(int, int), ImageMask.Clone(), ImageMask.GetFeathered(FeatheringSettings), ImageMask.Apply(), ImageMask.ApplyTo(RasterImage), ImageMask.Invert(), ImageMask.Union(ImageMask), ImageMask.Union(MagicWandSettings), ImageMask.Union(RasterImage, MagicWandSettings), ImageMask.Subtract(ImageMask), ImageMask.Subtract(MagicWandSettings), ImageMask.Subtract(RasterImage, MagicWandSettings), ImageMask.Intersect(ImageMask), ImageMask.Intersect(MagicWandSettings), ImageMask.Intersect(RasterImage, MagicWandSettings), ImageMask.ExclusiveDisjunction(ImageMask), ImageMask.ExclusiveDisjunction(MagicWandSettings), ImageMask.ExclusiveDisjunction(RasterImage, MagicWandSettings), ImageMask.Source, ImageMask.Width, ImageMask.Height, ImageMask.Bounds, ImageMask.SelectionBounds, ImageMask.this[int, int], 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_RectangleMask__ctor_System_Int32_System_Int32_System_Int32_System_Int32_"></a> RectangleMask\(int, int, int, int\)
Initializes a new instance of the Aspose.Imaging.MagicWand.ImageMasks.RectangleMask class with the specified left-top point, width and height.
```csharp
public RectangleMask(int x, int y, int width, int height)
Parameters
x
int
The x-coordinate of the left-top point of the selected area.
y
int
The y-coordinate of the left-top point of the selected area.
width
int
Width of the selected area.
height
int
Height of the selected area.
RectangleMask(Rectangle)
Initializes a new instance of the Aspose.Imaging.MagicWand.ImageMasks.RectangleMask class with the specified rectangle.
public RectangleMask(Rectangle selectedArea)
Parameters
selectedArea
Rectangle
Selected area specified as a rectangle.
Properties
SelectionBounds
Gets the bounds of the selected part of the mask, in pixels.
public override Rectangle SelectionBounds { get; }
Property Value
this[int, int]
Gets the opacity of the specified pixel.
public override bool this[int x, int y] { get; }
Property Value
Methods
Clone()
Creates a new object that is a copy of the current instance.
public override object Clone()
Returns
A new object that is a copy of this instance.
Crop(Rectangle)
Crops mask with the specified rectangle.
public override ImageMask Crop(Rectangle rectangle)
Parameters
rectangle
Rectangle
The specified rectangle.
Returns
A cropped RectangleMask as ImageMask.
Inflate(int)
Inflates this mask by the specified amount.
public override ImageMask Inflate(int size)
Parameters
size
int
The amount to inflate this mask.
Returns
An inflated RectangleMask as ImageMask.