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

ConstructorDescription
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

MethodDescription
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:

ParameterTypeDescription
widthintWidth of the mask.
heightintHeight 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:

ParameterTypeDescription
imageRasterImageSource 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:

ParameterTypeDescription
xintThe x-coordinate of the pixel.
yintThe 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:

ParameterTypeDescription
xintThe x-coordinate of the pixel.
yintThe y-coordinate of the pixel. Value: Byte value; 0 if transparent; 255 if opaque.
valuebytethe 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:

ParameterTypeDescription
xintThe x-coordinate of the pixel.
yintThe 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:

ParameterTypeDescription
xintThe x-coordinate of the pixel.
yintThe 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:

ParameterTypeDescription
xintThe x-coordinate of the pixel.
yintThe 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:

ParameterTypeDescription
imageRasterImageImage to apply mask to.

crop(Size size)

public final ImageGrayscaleMask crop(Size size)

Crops mask with the specified size.

Parameters:

ParameterTypeDescription
sizeSizeThe 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:

ParameterTypeDescription
widthintThe specified width.
heightintThe specified height.

Returns: ImageGrayscaleMask - A cropped ImageGrayscaleMask.

crop(Rectangle rectangle)

public final ImageGrayscaleMask crop(Rectangle rectangle)

Crops mask with the specified rectangle.

Parameters:

ParameterTypeDescription
rectangleRectangleThe 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:

ParameterTypeDescription
maskImageGrayscaleMaskProvided mask

Returns: ImageGrayscaleMask - New ImageGrayscaleMask.

subtract(ImageGrayscaleMask mask)

public final ImageGrayscaleMask subtract(ImageGrayscaleMask mask)

Gets the subtraction of the provided mask from current.

Parameters:

ParameterTypeDescription
maskImageGrayscaleMaskProvided mask

Returns: ImageGrayscaleMask - New ImageGrayscaleMask.

intersect(ImageGrayscaleMask mask)

public final ImageGrayscaleMask intersect(ImageGrayscaleMask mask)

Gets the intersection of current mask with provided.

Parameters:

ParameterTypeDescription
maskImageGrayscaleMaskProvided mask

Returns: ImageGrayscaleMask - New ImageGrayscaleMask.

exclusiveDisjunction(ImageGrayscaleMask mask)

public final ImageGrayscaleMask exclusiveDisjunction(ImageGrayscaleMask mask)

Gets the exclusive disjunction of current mask with provided.

Parameters:

ParameterTypeDescription
maskImageGrayscaleMaskProvided mask

Returns: ImageGrayscaleMask - New ImageGrayscaleMask.

op_LogicalNot(ImageGrayscaleMask a)

public static ImageGrayscaleMask op_LogicalNot(ImageGrayscaleMask a)

Inverts mask.

Parameters:

ParameterTypeDescription
aImageGrayscaleMaskThe 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:

ParameterTypeDescription
aImageGrayscaleMaskThe first mask.
bImageGrayscaleMaskThe 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:

ParameterTypeDescription
aImageGrayscaleMaskThe first mask.
bImageGrayscaleMaskThe 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:

ParameterTypeDescription
aImageGrayscaleMaskThe first mask.
bImageGrayscaleMaskThe 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:

ParameterTypeDescription
aImageGrayscaleMaskThe first mask.
bImageGrayscaleMaskThe second mask.

Returns: ImageGrayscaleMask - New ImageGrayscaleMask.