ImageMask
Inheritance: java.lang.Object
All Implemented Interfaces: com.aspose.imaging.magicwand.imagemasks.IImageMask
public abstract class ImageMask implements IImageMask
Describes a binary image mask.
Methods
Method | Description |
---|---|
getSource() | Gets the source image used to create this mask, if exists. |
getWidth() | Gets the width, in pixels, of this mask. |
getHeight() | Gets the height, in pixels, of this mask. |
getBounds() | Gets the bounds, in pixels, of this mask. |
getSelectionBounds() | Gets the bounds of the selected part of the mask, in pixels. |
get_Item(int x, int y) | Gets the opacity of the specified pixel. |
inflate(int size) | Inflates this mask by the specified amount. |
crop(Size size) | Crops mask with the specified size. |
crop(int width, int height) | Crops mask with the specified width and height. |
crop(Rectangle rectangle) | Crops mask with the specified rectangle. |
isOpaque(int x, int y) | Checks if the specified pixel is opaque. |
isTransparent(int x, int y) | Checks if the specified pixel is transparent. |
getByteOpacity(int x, int y) | Gets the opacity of the specified pixel with byte precision. |
deepClone() | Creates a new object that is a copy of the current instance. |
getFeathered() | Gets grayscale mask with the border feathered with the default settings. |
getFeathered(FeatheringSettings settings) | Gets grayscale mask with the border feathered with the specified settings. |
apply() | Applies current mask to the RasterImage source, if exists. |
applyTo(RasterImage image) | Applies current mask to the specified RasterImage. |
invert() | Gets the inversion of the current mask. |
union(ImageMask mask) | Gets the union of the current mask with provided. |
union() | Gets the union of the current mask with the result of magic wand selection applied to the source of the mask. |
union(MagicWandSettings settings) | Gets the union of the current mask with the result of magic wand selection applied to the source of the mask. |
union(RasterImage image) | Gets the union of the current mask with the result of magic wand selection applied to the provided image. |
union(RasterImage image, MagicWandSettings settings) | Gets the union of the current mask with the result of magic wand selection applied to the provided image. |
subtract(ImageMask mask) | Gets the subtraction of the provided mask from current. |
subtract() | Gets the result of magic wand selection applied to the source of the current mask subtracted from the mask. |
subtract(MagicWandSettings settings) | Gets the result of magic wand selection applied to the source of the current mask subtracted from the mask. |
subtract(RasterImage image) | Gets the result of magic wand selection applied to the provided image subtracted from the current mask. |
subtract(RasterImage image, MagicWandSettings settings) | Gets the result of magic wand selection applied to the provided image subtracted from the current mask. |
intersect(ImageMask mask) | Gets the intersection of current mask with provided. |
intersect() | Gets the intersection of the current mask with the result of magic wand selection applied to the source of the mask. |
intersect(MagicWandSettings settings) | Gets the intersection of the current mask with the result of magic wand selection applied to the source of the mask. |
intersect(RasterImage image) | Gets the intersection of the current mask with the result of magic wand selection applied to the provided image. |
intersect(RasterImage image, MagicWandSettings settings) | Gets the intersection of the current mask with the result of magic wand selection applied to the provided image. |
exclusiveDisjunction(ImageMask mask) | Gets the exclusive disjunction of current mask with provided. |
exclusiveDisjunction() | Gets the exclusive disjunction of the current mask with the result of magic wand selection applied to the source of the mask. |
exclusiveDisjunction(MagicWandSettings settings) | Gets the exclusive disjunction of the current mask with the result of magic wand selection applied to the source of the mask. |
exclusiveDisjunction(RasterImage image) | Gets the exclusive disjunction of the current mask with the result of magic wand selection applied to the provided image. |
exclusiveDisjunction(RasterImage image, MagicWandSettings settings) | Gets the exclusive disjunction of the current mask with the result of magic wand selection applied to the provided image. |
to_ImageGrayscaleMask(ImageMask mask) | Casting mask to a ImageGrayscaleMask. |
op_LogicalNot(ImageMask a) | Inverts mask. |
op_Addition(ImageMask a, ImageMask b) | Union of two masks. |
op_Subtraction(ImageMask a, ImageMask b) | Subtract second mask from first. |
op_Multiply(ImageMask a, ImageMask b) | Intersection of two masks. |
op_ExclusiveOr(ImageMask a, ImageMask b) | Exclusive disjunction of two masks. |
Example: 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, subtract).
String imageFilePath = "input.png";
String outputFilePath = "masked-complex.png";
try (RasterImage image = (RasterImage)Image.load(imageFilePath))
{
// 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) {{ setThreshold(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() {{ setSize(3); }})
// Apply mask to the image
.apply();
// Save image
image.save(outputFilePath);
}
getSource()
public final RasterImage getSource()
Gets the source image used to create this mask, if exists.
Returns: RasterImage - the source image used to create this mask, if exists.
getWidth()
public final int getWidth()
Gets the width, in pixels, of this mask.
Returns: int - the width, in pixels, of this mask.
getHeight()
public final int getHeight()
Gets the height, in pixels, of this mask.
Returns: int - the height, in pixels, of this mask.
getBounds()
public final Rectangle getBounds()
Gets the bounds, in pixels, of this mask.
Returns: Rectangle - the bounds, in pixels, of this mask.
getSelectionBounds()
public abstract Rectangle getSelectionBounds()
Gets the bounds of the selected part of the mask, in pixels.
Returns: Rectangle - the bounds of the selected part of the mask, in pixels.
get_Item(int x, int y)
public abstract boolean get_Item(int x, int y)
Gets the opacity of the specified pixel.
Parameters:
Parameter | Type | Description |
---|---|---|
x | int | The x-coordinate of the pixel. |
y | int | The y-coordinate of the pixel. |
Returns: boolean - true if the specified pixel is opaque; otherwise, false.
inflate(int size)
public abstract ImageMask inflate(int size)
Inflates this mask by the specified amount.
Parameters:
Parameter | Type | Description |
---|---|---|
size | int | The amount to inflate this mask. |
Returns: ImageMask - An ImageMask.
crop(Size size)
public final ImageMask crop(Size size)
Crops mask with the specified size.
Parameters:
Parameter | Type | Description |
---|---|---|
size | Size | The specified size. |
Returns: ImageMask - An ImageMask.
crop(int width, int height)
public final ImageMask crop(int width, int height)
Crops mask with the specified width and height.
Parameters:
Parameter | Type | Description |
---|---|---|
width | int | The specified width. |
height | int | The specified height. |
Returns: ImageMask - An ImageMask.
crop(Rectangle rectangle)
public abstract ImageMask crop(Rectangle rectangle)
Crops mask with the specified rectangle.
Parameters:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The specified rectangle. |
Returns: ImageMask - An ImageMask.
isOpaque(int x, int y)
public final boolean isOpaque(int x, int y)
Checks if the specified pixel is opaque.
Parameters:
Parameter | Type | Description |
---|---|---|
x | int | The x-coordinate of the pixel. |
y | int | The y-coordinate of the pixel. |
Returns: boolean - true if the specified pixel is opaque; otherwise, false.
isTransparent(int x, int y)
public final boolean isTransparent(int x, int y)
Checks if the specified pixel is transparent.
Parameters:
Parameter | Type | Description |
---|---|---|
x | int | The x-coordinate of the pixel. |
y | int | The y-coordinate of the pixel. |
Returns: boolean - true if the specified pixel is transparent; otherwise, false.
getByteOpacity(int x, int y)
public final byte getByteOpacity(int x, int y)
Gets the opacity of the specified pixel with byte precision.
Parameters:
Parameter | Type | Description |
---|---|---|
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.
deepClone()
public abstract Object deepClone()
Creates a new object that is a copy of the current instance.
Returns: java.lang.Object - A new object that is a copy of this instance.
getFeathered()
public final ImageGrayscaleMask getFeathered()
Gets grayscale mask with the border feathered with the default settings.
Returns: ImageGrayscaleMask - .to_ImageGrayscaleMask(ImageMask)} with feathered border.
getFeathered(FeatheringSettings settings)
public final ImageGrayscaleMask getFeathered(FeatheringSettings settings)
Gets grayscale mask with the border feathered with the specified settings.
Parameters:
Parameter | Type | Description |
---|---|---|
settings | FeatheringSettings | Feathering settings. |
Returns: ImageGrayscaleMask - .to_ImageGrayscaleMask(ImageMask)} with feathered border.
apply()
public final void apply()
Applies current mask to the RasterImage source, if exists.
Example: The example shows how to select a simple area of an image based on tone and color of any pixel using Magic Wand tool.
String imageFilePath = "input.png";
String outputFilePath = "masked.png";
try (RasterImage image = (RasterImage)Image.load(imageFilePath))
{
// Create a new mask using magic wand tool based on tone and color of pixel (120, 100) with custom threshold equal to 150
MagicWandTool
.select(image, new MagicWandSettings(120, 100) {{ setThreshold(150); }})
// Apply mask to the image
.apply();
// Save image with forced transparency color type option
image.save(outputFilePath, new PngOptions()
{{
setColorType(PngColorType.TruecolorWithAlpha);
}});
}
applyTo(RasterImage image)
public final void applyTo(RasterImage image)
Applies current mask to the specified RasterImage.
Parameters:
Parameter | Type | Description |
---|---|---|
image | RasterImage | Image to apply mask to. |
invert()
public final ImageBitMask invert()
Gets the inversion of the current mask.
Returns: ImageBitMask - New ImageBitMask.
Example: 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, subtract).
String imageFilePath = "input.png";
String outputFilePath = "masked-complex.png";
try (RasterImage image = (RasterImage)Image.load(imageFilePath))
{
// 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) {{ setThreshold(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() {{ setSize(3); }})
// Apply mask to the image
.apply();
// Save image
image.save(outputFilePath);
}
union(ImageMask mask)
public final ImageBitMask union(ImageMask mask)
Gets the union of the current mask with provided.
Parameters:
Parameter | Type | Description |
---|---|---|
mask | ImageMask | Provided mask |
Returns: ImageBitMask - New ImageBitMask.
union()
public final ImageBitMask union()
Gets the union of the current mask with the result of magic wand selection applied to the source of the mask.
Returns: ImageBitMask - New ImageBitMask.
union(MagicWandSettings settings)
public final ImageBitMask union(MagicWandSettings settings)
Gets the union of the current mask with the result of magic wand selection applied to the source of the mask.
Parameters:
Parameter | Type | Description |
---|---|---|
settings | MagicWandSettings | Magic wand settings. |
Returns: ImageBitMask - New ImageBitMask.
union(RasterImage image)
public final ImageBitMask union(RasterImage image)
Gets the union of the current mask with the result of magic wand selection applied to the provided image.
Parameters:
Parameter | Type | Description |
---|---|---|
image | RasterImage | Image for magic wand. |
Returns: ImageBitMask - New ImageBitMask.
union(RasterImage image, MagicWandSettings settings)
public final ImageBitMask union(RasterImage image, MagicWandSettings settings)
Gets the union of the current mask with the result of magic wand selection applied to the provided image.
Parameters:
Parameter | Type | Description |
---|---|---|
image | RasterImage | Image for magic wand. |
settings | MagicWandSettings | Magic wand settings. |
Returns: ImageBitMask - New ImageBitMask.
subtract(ImageMask mask)
public final ImageBitMask subtract(ImageMask mask)
Gets the subtraction of the provided mask from current.
Parameters:
Parameter | Type | Description |
---|---|---|
mask | ImageMask | Provided mask |
Returns: ImageBitMask - New ImageBitMask.
subtract()
public final ImageBitMask subtract()
Gets the result of magic wand selection applied to the source of the current mask subtracted from the mask.
Returns: ImageBitMask - New ImageBitMask.
subtract(MagicWandSettings settings)
public final ImageBitMask subtract(MagicWandSettings settings)
Gets the result of magic wand selection applied to the source of the current mask subtracted from the mask.
Parameters:
Parameter | Type | Description |
---|---|---|
settings | MagicWandSettings | Magic wand settings. |
Returns: ImageBitMask - New ImageBitMask.
subtract(RasterImage image)
public final ImageBitMask subtract(RasterImage image)
Gets the result of magic wand selection applied to the provided image subtracted from the current mask.
Parameters:
Parameter | Type | Description |
---|---|---|
image | RasterImage | Image for magic wand. |
Returns: ImageBitMask - New ImageBitMask.
subtract(RasterImage image, MagicWandSettings settings)
public final ImageBitMask subtract(RasterImage image, MagicWandSettings settings)
Gets the result of magic wand selection applied to the provided image subtracted from the current mask.
Parameters:
Parameter | Type | Description |
---|---|---|
image | RasterImage | Image for magic wand. |
settings | MagicWandSettings | Magic wand settings. |
Returns: ImageBitMask - New ImageBitMask.
intersect(ImageMask mask)
public final ImageBitMask intersect(ImageMask mask)
Gets the intersection of current mask with provided.
Parameters:
Parameter | Type | Description |
---|---|---|
mask | ImageMask | Provided mask |
Returns: ImageBitMask - New ImageBitMask.
intersect()
public final ImageBitMask intersect()
Gets the intersection of the current mask with the result of magic wand selection applied to the source of the mask.
Returns: ImageBitMask - New ImageBitMask.
intersect(MagicWandSettings settings)
public final ImageBitMask intersect(MagicWandSettings settings)
Gets the intersection of the current mask with the result of magic wand selection applied to the source of the mask.
Parameters:
Parameter | Type | Description |
---|---|---|
settings | MagicWandSettings | Magic wand settings. |
Returns: ImageBitMask - New ImageBitMask.
intersect(RasterImage image)
public final ImageBitMask intersect(RasterImage image)
Gets the intersection of the current mask with the result of magic wand selection applied to the provided image.
Parameters:
Parameter | Type | Description |
---|---|---|
image | RasterImage | Image for magic wand. |
Returns: ImageBitMask - New ImageBitMask.
intersect(RasterImage image, MagicWandSettings settings)
public final ImageBitMask intersect(RasterImage image, MagicWandSettings settings)
Gets the intersection of the current mask with the result of magic wand selection applied to the provided image.
Parameters:
Parameter | Type | Description |
---|---|---|
image | RasterImage | Image for magic wand. |
settings | MagicWandSettings | Magic wand settings. |
Returns: ImageBitMask - New ImageBitMask.
exclusiveDisjunction(ImageMask mask)
public final ImageBitMask exclusiveDisjunction(ImageMask mask)
Gets the exclusive disjunction of current mask with provided.
Parameters:
Parameter | Type | Description |
---|---|---|
mask | ImageMask | Provided mask |
Returns: ImageBitMask - New ImageBitMask.
exclusiveDisjunction()
public final ImageBitMask exclusiveDisjunction()
Gets the exclusive disjunction of the current mask with the result of magic wand selection applied to the source of the mask.
Returns: ImageBitMask - New ImageBitMask.
exclusiveDisjunction(MagicWandSettings settings)
public final ImageBitMask exclusiveDisjunction(MagicWandSettings settings)
Gets the exclusive disjunction of the current mask with the result of magic wand selection applied to the source of the mask.
Parameters:
Parameter | Type | Description |
---|---|---|
settings | MagicWandSettings | Magic wand settings. |
Returns: ImageBitMask - New ImageBitMask.
exclusiveDisjunction(RasterImage image)
public final ImageBitMask exclusiveDisjunction(RasterImage image)
Gets the exclusive disjunction of the current mask with the result of magic wand selection applied to the provided image.
Parameters:
Parameter | Type | Description |
---|---|---|
image | RasterImage | Image for magic wand. |
Returns: ImageBitMask - New ImageBitMask.
exclusiveDisjunction(RasterImage image, MagicWandSettings settings)
public final ImageBitMask exclusiveDisjunction(RasterImage image, MagicWandSettings settings)
Gets the exclusive disjunction of the current mask with the result of magic wand selection applied to the provided image.
Parameters:
Parameter | Type | Description |
---|---|---|
image | RasterImage | Image for magic wand. |
settings | MagicWandSettings | Magic wand settings. |
Returns: ImageBitMask - New ImageBitMask.
to_ImageGrayscaleMask(ImageMask mask)
public static ImageGrayscaleMask to_ImageGrayscaleMask(ImageMask mask)
Casting mask
to a ImageGrayscaleMask.
Parameters:
Parameter | Type | Description |
---|---|---|
mask | ImageMask | The mask value. |
Returns:
ImageGrayscaleMask - The new ImageGrayscaleMask base on mask
.
op_LogicalNot(ImageMask a)
public static ImageBitMask op_LogicalNot(ImageMask a)
Inverts mask.
Parameters:
Parameter | Type | Description |
---|---|---|
a | ImageMask | The mask to be inverted. |
Returns: ImageBitMask - New ImageBitMask.
op_Addition(ImageMask a, ImageMask b)
public static ImageBitMask op_Addition(ImageMask a, ImageMask b)
Union of two masks.
Parameters:
Parameter | Type | Description |
---|---|---|
a | ImageMask | The first mask. |
b | ImageMask | The second mask. |
Returns: ImageBitMask - New ImageBitMask.
op_Subtraction(ImageMask a, ImageMask b)
public static ImageBitMask op_Subtraction(ImageMask a, ImageMask b)
Subtract second mask from first.
Parameters:
Parameter | Type | Description |
---|---|---|
a | ImageMask | The first mask. |
b | ImageMask | The second mask. |
Returns: ImageBitMask - New ImageBitMask.
op_Multiply(ImageMask a, ImageMask b)
public static ImageBitMask op_Multiply(ImageMask a, ImageMask b)
Intersection of two masks.
Parameters:
Parameter | Type | Description |
---|---|---|
a | ImageMask | The first mask. |
b | ImageMask | The second mask. |
Returns: ImageBitMask - New ImageBitMask.
op_ExclusiveOr(ImageMask a, ImageMask b)
public static ImageBitMask op_ExclusiveOr(ImageMask a, ImageMask b)
Exclusive disjunction of two masks.
Parameters:
Parameter | Type | Description |
---|---|---|
a | ImageMask | The first mask. |
b | ImageMask | The second mask. |
Returns: ImageBitMask - New ImageBitMask.