public class MagicWandSettings extends Object
A magic wand selection settings class.
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);
}});
}
| Modifier and Type | Class and Description |
|---|---|
static interface |
MagicWandSettings.ColorComparison
Delegate for
Color comparison with a defined threshold. |
| Constructor and Description |
|---|
MagicWandSettings(int x,
int y)
Initializes a new instance of the
MagicWandSettings class. |
MagicWandSettings(Point point)
Initializes a new instance of the
MagicWandSettings class. |
| Modifier and Type | Method and Description |
|---|---|
Rectangle |
getAreaOfInterest()
Gets the bounds of the area for algorithm work.
|
int |
getColorCompareMode()
Gets the algorithm how colors are compared.
|
MagicWandSettings.ColorComparison |
getColorComparisonDelegate()
Gets the custom color comparison algorithm if
ColorCompareMode(MagicWandSettings.getColorCompareMode()/MagicWandSettings.setColorCompareMode(int)) is set to ColorComparisonMode.Custom. |
boolean |
getContiguousMode()
Gets a value indicating whether magic wand will define only contiguous pixels.
|
int |
getDirectionalMode()
Gets the mode of flood fill search algorithm: four of eight direction search.
|
Point |
getPoint()
Gets the reference point for algorithm work.
|
int |
getThreshold()
Gets the tolerance level for pixels color comparison.
|
void |
setAreaOfInterest(Rectangle value)
Sets the bounds of the area for algorithm work.
|
void |
setColorCompareMode(int value)
Sets the algorithm how colors are compared.
|
void |
setColorComparisonDelegate(MagicWandSettings.ColorComparison value)
Sets the custom color comparison algorithm if
ColorCompareMode(MagicWandSettings.getColorCompareMode()/MagicWandSettings.setColorCompareMode(int)) is set to ColorComparisonMode.Custom. |
void |
setContiguousMode(boolean value)
Sets a value indicating whether magic wand will define only contiguous pixels.
|
void |
setDirectionalMode(int value)
Sets the mode of flood fill search algorithm: four of eight direction search.
|
void |
setThreshold(int value)
Sets the tolerance level for pixels color comparison.
|
public MagicWandSettings(Point point)
Initializes a new instance of the MagicWandSettings class.
point - The reference point.public MagicWandSettings(int x,
int y)
Initializes a new instance of the MagicWandSettings class.
x - The x-coordinate of the reference point.y - The y-coordinate of the reference point.public final Rectangle getAreaOfInterest()
Gets the bounds of the area for algorithm work.
Value: The rectangle representing the bounds of the area of interest.public final void setAreaOfInterest(Rectangle value)
Sets the bounds of the area for algorithm work.
Value: The rectangle representing the bounds of the area of interest.value - the bounds of the area for algorithm work.public final Point getPoint()
Gets the reference point for algorithm work.
Value: ThePoint value.public final int getThreshold()
Gets the tolerance level for pixels color comparison.
Value: The threshold for color comparing.public final void setThreshold(int value)
Sets the tolerance level for pixels color comparison.
Value: The threshold for color comparing.value - the tolerance level for pixels color comparison.public final boolean getContiguousMode()
Gets a value indicating whether magic wand will define only contiguous pixels.
Value:true if the element is enabled; otherwise, false. The default value is true.public final void setContiguousMode(boolean value)
Sets a value indicating whether magic wand will define only contiguous pixels.
Value:true if the element is enabled; otherwise, false. The default value is true.value - a value indicating whether magic wand will define only contiguous pixels.public final int getDirectionalMode()
Gets the mode of flood fill search algorithm: four of eight direction search.
Value: The mode of flood fill search algorithm.public final void setDirectionalMode(int value)
Sets the mode of flood fill search algorithm: four of eight direction search.
Value: The mode of flood fill search algorithm.value - the mode of flood fill search algorithm: four of eight direction search.public final int getColorCompareMode()
Gets the algorithm how colors are compared.
Value: The color compare mode.public final void setColorCompareMode(int value)
Sets the algorithm how colors are compared.
Value: The color compare mode.value - the algorithm how colors are compared.public final MagicWandSettings.ColorComparison getColorComparisonDelegate()
Gets the custom color comparison algorithm if ColorCompareMode(MagicWandSettings.getColorCompareMode()/MagicWandSettings.setColorCompareMode(int)) is set to ColorComparisonMode.Custom.
ColorCompareMode(MagicWandSettings.getColorCompareMode()/MagicWandSettings.setColorCompareMode(int)) is set to ColorComparisonMode.Custom.public final void setColorComparisonDelegate(MagicWandSettings.ColorComparison value)
Sets the custom color comparison algorithm if ColorCompareMode(MagicWandSettings.getColorCompareMode()/MagicWandSettings.setColorCompareMode(int)) is set to ColorComparisonMode.Custom.
value - the custom color comparison algorithm if ColorCompareMode(MagicWandSettings.getColorCompareMode()/MagicWandSettings.setColorCompareMode(int)) is set to ColorComparisonMode.Custom.Copyright (c) 2008-2025 Aspose Pty Ltd. All Rights Reserved.