public class MagicWandTool extends Object implements IPartialArgb32PixelLoader
The class for magic wand algorithm main logic.
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 | Method and Description |
|---|---|
void |
process(Rectangle pixelsRectangle,
int[] pixels,
Point start,
Point end)
Processes the loaded pixels .
|
static ImageBitMask |
select(RasterImage source,
MagicWandSettings settings)
|
public static ImageBitMask select(RasterImage source, MagicWandSettings settings)
Creates a new ImageBitMask based on MagicWandSettings and source RasterImage.
source - Raster image for the algorithm to work over.settings - Settings of magic wand algorithm used in creating mask.ImageBitMask.public final void process(Rectangle pixelsRectangle, int[] pixels, Point start, Point end)
Processes the loaded pixels .
process in interface IPartialArgb32PixelLoaderpixelsRectangle - The pixels rectangle.pixels - The 32-bit ARGB pixels.start - The start pixels point. If not equal to (left,top) meaning that it is not full rectangle we have.end - The end pixels point. If not equal to (right,bottom) meaning that it is not full rectangle we have.Copyright (c) 2008-2025 Aspose Pty Ltd. All Rights Reserved.