ImageGrayscaleMask
Inheritance: java.lang.Object
All Implemented Interfaces: com.aspose.imaging.magicwand.imagemasks.IImageMask
public class ImageGrayscaleMask implements IImageMask
Describes a grayscale image mask.
Constructors
Constructor | Description |
---|---|
ImageGrayscaleMask(int width, int height) | Initializes a new instance of the ImageGrayscaleMask class with the specified width and height. |
ImageGrayscaleMask(RasterImage image) | Initializes a new instance of the ImageGrayscaleMask class with the size of the specified existing RasterImage. |
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. |
set_Item(int x, int y, byte value) | Sets the opacity of the specified pixel. |
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. |
apply() | Applies current mask to the RasterImage source, if exists. |
applyTo(RasterImage image) | Applies current mask to the specified RasterImage. |
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. |
invert() | Gets the inversion of the current mask. |
union(ImageGrayscaleMask mask) | Union of two masks. |
subtract(ImageGrayscaleMask mask) | Gets the subtraction of the provided mask from current. |
intersect(ImageGrayscaleMask mask) | Gets the intersection of current mask with provided. |
exclusiveDisjunction(ImageGrayscaleMask mask) | Gets the exclusive disjunction of current mask with provided. |
op_LogicalNot(ImageGrayscaleMask a) | Inverts mask. |
op_Addition(ImageGrayscaleMask a, ImageGrayscaleMask b) | Union of two masks. |
op_Subtraction(ImageGrayscaleMask a, ImageGrayscaleMask b) | Subtract second mask from first. |
op_Multiply(ImageGrayscaleMask a, ImageGrayscaleMask b) | Intersection of two masks. |
op_ExclusiveOr(ImageGrayscaleMask a, ImageGrayscaleMask 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);
}
ImageGrayscaleMask(int width, int height)
public ImageGrayscaleMask(int width, int height)
Initializes a new instance of the ImageGrayscaleMask class with the specified width and height.
Parameters:
Parameter | Type | Description |
---|---|---|
width | int | Width of the mask. |
height | int | Height of the mask. |
ImageGrayscaleMask(RasterImage image)
public ImageGrayscaleMask(RasterImage image)
Initializes a new instance of the ImageGrayscaleMask class with the size of the specified existing RasterImage. Specified RasterImage will be stored as source image.
Parameters:
Parameter | Type | Description |
---|---|---|
image | RasterImage | Source image. |
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 final 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 final byte 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. Value: Byte value; 0 if transparent; 255 if opaque. |
Returns: byte
set_Item(int x, int y, byte value)
public final void set_Item(int x, int y, byte value)
Sets 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. Value: Byte value; 0 if transparent; 255 if opaque. |
value | byte | the opacity of the specified pixel. |
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 final 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.
apply()
public final void apply()
Applies current mask to the RasterImage source, if exists.
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. |
crop(Size size)
public final ImageGrayscaleMask crop(Size size)
Crops mask with the specified size.
Parameters:
Parameter | Type | Description |
---|---|---|
size | Size | The specified size. |
Returns: ImageGrayscaleMask - A cropped ImageGrayscaleMask.
crop(int width, int height)
public final ImageGrayscaleMask 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: ImageGrayscaleMask - A cropped ImageGrayscaleMask.
crop(Rectangle rectangle)
public final ImageGrayscaleMask crop(Rectangle rectangle)
Crops mask with the specified rectangle.
Parameters:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The specified rectangle. |
Returns: ImageGrayscaleMask - A cropped ImageGrayscaleMask.
invert()
public final ImageGrayscaleMask invert()
Gets the inversion of the current mask.
Returns: ImageGrayscaleMask - New ImageGrayscaleMask.
union(ImageGrayscaleMask mask)
public final ImageGrayscaleMask union(ImageGrayscaleMask mask)
Union of two masks.
Parameters:
Parameter | Type | Description |
---|---|---|
mask | ImageGrayscaleMask | Provided mask |
Returns: ImageGrayscaleMask - New ImageGrayscaleMask.
subtract(ImageGrayscaleMask mask)
public final ImageGrayscaleMask subtract(ImageGrayscaleMask mask)
Gets the subtraction of the provided mask from current.
Parameters:
Parameter | Type | Description |
---|---|---|
mask | ImageGrayscaleMask | Provided mask |
Returns: ImageGrayscaleMask - New ImageGrayscaleMask.
intersect(ImageGrayscaleMask mask)
public final ImageGrayscaleMask intersect(ImageGrayscaleMask mask)
Gets the intersection of current mask with provided.
Parameters:
Parameter | Type | Description |
---|---|---|
mask | ImageGrayscaleMask | Provided mask |
Returns: ImageGrayscaleMask - New ImageGrayscaleMask.
exclusiveDisjunction(ImageGrayscaleMask mask)
public final ImageGrayscaleMask exclusiveDisjunction(ImageGrayscaleMask mask)
Gets the exclusive disjunction of current mask with provided.
Parameters:
Parameter | Type | Description |
---|---|---|
mask | ImageGrayscaleMask | Provided mask |
Returns: ImageGrayscaleMask - New ImageGrayscaleMask.
op_LogicalNot(ImageGrayscaleMask a)
public static ImageGrayscaleMask op_LogicalNot(ImageGrayscaleMask a)
Inverts mask.
Parameters:
Parameter | Type | Description |
---|---|---|
a | ImageGrayscaleMask | The mask to be inverted. |
Returns: ImageGrayscaleMask - New ImageGrayscaleMask.
op_Addition(ImageGrayscaleMask a, ImageGrayscaleMask b)
public static ImageGrayscaleMask op_Addition(ImageGrayscaleMask a, ImageGrayscaleMask b)
Union of two masks.
Parameters:
Parameter | Type | Description |
---|---|---|
a | ImageGrayscaleMask | The first mask. |
b | ImageGrayscaleMask | The second mask. |
Returns: ImageGrayscaleMask - New ImageGrayscaleMask.
op_Subtraction(ImageGrayscaleMask a, ImageGrayscaleMask b)
public static ImageGrayscaleMask op_Subtraction(ImageGrayscaleMask a, ImageGrayscaleMask b)
Subtract second mask from first.
Parameters:
Parameter | Type | Description |
---|---|---|
a | ImageGrayscaleMask | The first mask. |
b | ImageGrayscaleMask | The second mask. |
Returns: ImageGrayscaleMask - New ImageGrayscaleMask.
op_Multiply(ImageGrayscaleMask a, ImageGrayscaleMask b)
public static ImageGrayscaleMask op_Multiply(ImageGrayscaleMask a, ImageGrayscaleMask b)
Intersection of two masks.
Parameters:
Parameter | Type | Description |
---|---|---|
a | ImageGrayscaleMask | The first mask. |
b | ImageGrayscaleMask | The second mask. |
Returns: ImageGrayscaleMask - New ImageGrayscaleMask.
op_ExclusiveOr(ImageGrayscaleMask a, ImageGrayscaleMask b)
public static ImageGrayscaleMask op_ExclusiveOr(ImageGrayscaleMask a, ImageGrayscaleMask b)
Exclusive disjunction of two masks.
Parameters:
Parameter | Type | Description |
---|---|---|
a | ImageGrayscaleMask | The first mask. |
b | ImageGrayscaleMask | The second mask. |
Returns: ImageGrayscaleMask - New ImageGrayscaleMask.