Class MagicWandTool
Namespace: Aspose.Imaging.MagicWand
Assembly: Aspose.Imaging.dll (25.7.0)
The class for magic wand algorithm main logic.
public class MagicWandTool : IP partialArgb32PixelLoader
{
public void Load(Image image, int x, int y, int width, int height, Argb32[] pixels)
{
}
}
Inheritance
Implements
Inherited Members
object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Examples
The example shows how to select a simple area of an image based on tone and color of any pixel using Magic Wand tool.
var imageFilePath = "input.png";
using (RasterImage image = Image.Load(imageFilePath))
{
var maskSettings = new MagicWandSettings(120, 100) { Threshold = 150 };
MagicWandTool.Select(image, maskSettings);
MagicWandTool.Apply();
image.Save(outputFilePath, new ImageOptions().PngOptions()
{
ColorType = PngColorType.TruecolorWithAlpha
});
}
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, substract).
var imageFilePath = "input.png";
using (RasterImage image = (RasterImage)Image.Load(imageFilePath))
{
image.MagicWandTool.Select(new MagicWandSettings(845, 128));
image.MagicWandTool.Union(new MagicWandSettings(416, 387));
image.MagicWandTool.Invert();
image.MagicWandTool.Subtract(new MagicWandSettings(1482, 346) { Threshold = 69 });
image.MagicWandTool.Subtract(new RectangleMask(0, 0, 800, 150));
image.MagicWandTool.Subtract(new RectangleMask(0, 380, 600, 220));
image.MagicWandTool.Subtract(new RectangleMask(930, 520, 110, 40));
image.MagicWandTool.Subtract(new RectangleMask(1370, 400, 120, 200));
image.MagicWandTool.GetFeathered(new FeatheringSettings() { Size = 3 });
image.MagicWandTool.Apply();
image.Save(outputFilePath);
}
Methods
Process(Rectangle, int[], Point, Point)
Processes the loaded pixels .
public void Process(
Rectangle pixelsRectangle,
int[] pixels,
Point start,
Point end)
{
}
Parameters
pixelsRectangle
Rectangle
The pixels rectangle.
pixels
int
[]
The 32-bit ARGB pixels.
start
Point
The start pixels point. If not equal to (left,top) meaning that it is not full rectangle we have.
end
Point
The end pixels point. If not equal to (right,bottom) meaning that it is not full rectangle we have.
Select(RasterImage, MagicWandSettings)
Creates a new Aspose.Imaging.MagicWand.ImageMasks.ImageBitMask based on Aspose.Imaging.MagicWand.MagicWandSettings and source Aspose.Imaging.RasterImage.
public static ImageBitMask Select(RasterImage source, MagicWandSettings settings)
{
}
In this case, no changes are required as the code is already formatted according to standard C# conventions. However, if there were inconsistencies in indentation, spacing, or readability, they would be corrected without altering the logic, variable names, or library-specific knowledge.
Parameters
source
RasterImage
Raster image for the algorithm to work over.
settings
MagicWandSettings
Settings of magic wand algorithm used in creating mask.
Returns
New Aspose.Imaging.MagicWand.ImageMasks.ImageBitMask.