Packages

 

com.aspose.imaging.masking.options

Class ManualMaskingArgs

  • All Implemented Interfaces:
    IMaskingArgs


    public class ManualMaskingArgs
    extends Object
    implements IMaskingArgs

    Represents the arguments that are specified for manual masking method

    See Also:
    IMaskingArgs
    Code example:

    This example shows how to decompose a raster image into multiple images using image masking and a manual mask. Image masking is an image processing technique that is used to split the background from the foreground image objects.


    String dir = "c:\\temp\\";
    
    // Define a manual mask.
    com.aspose.imaging.GraphicsPath manualMask = new com.aspose.imaging.GraphicsPath();
    com.aspose.imaging.Figure figure = new com.aspose.imaging.Figure();
    figure.addShape(new com.aspose.imaging.shapes.EllipseShape(new com.aspose.imaging.RectangleF(50, 50, 40, 40)));
    figure.addShape(new com.aspose.imaging.shapes.RectangleShape(new com.aspose.imaging.RectangleF(10, 20, 50, 30)));
    manualMask.addFigure(figure);
    
    // Set the manual mask.
    com.aspose.imaging.masking.options.ManualMaskingArgs args = new com.aspose.imaging.masking.options.ManualMaskingArgs();
    args.setMask(manualMask);
    
    com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.load(dir + "Blue hills.png");
    try {
        com.aspose.imaging.masking.options.MaskingOptions maskingOptions = new com.aspose.imaging.masking.options.MaskingOptions();
    
        // Use manual clustering algorithm.
        maskingOptions.setMethod(com.aspose.imaging.masking.options.SegmentationMethod.Manual);
    
        // All shapes making up a mask will be combined into one.
        maskingOptions.setDecompose(false);
        maskingOptions.setArgs(args);
    
        // A maximum expected size of the TrueColor with Alpha PNG image.
        int estimatedMaxImageSize = image.getWidth() * image.getHeight() * 4;
    
        // Each cluster (segment) will be stored to a separate PNG file.
        com.aspose.imaging.imageoptions.PngOptions exportOptions = new com.aspose.imaging.imageoptions.PngOptions();
        exportOptions.setColorType(com.aspose.imaging.fileformats.png.PngColorType.TruecolorWithAlpha);
        exportOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[estimatedMaxImageSize])));
    
        // The backgroung color will be orange.
        maskingOptions.setBackgroundReplacementColor(com.aspose.imaging.Color.getOrange());
        maskingOptions.setExportOptions(exportOptions);
    
        // The area of the source image that masking will be applied to.
        maskingOptions.setMaskingArea(new com.aspose.imaging.Rectangle(50, 50, 120, 120));
    
        // Create an instance of the ImageMasking class.
        com.aspose.imaging.masking.ImageMasking masking = new com.aspose.imaging.masking.ImageMasking(image);
    
        // Divide the source image into several clusters (segments).
        com.aspose.imaging.masking.result.MaskingResult[] maskingResults = masking.decompose(maskingOptions);
    
        // Obtain images from masking result and save them to PNG.
        for (int i = 0; i < maskingResults.length; i++) {
            String outputFileName = String.format("Blue hills.Segment%s.png", maskingResults[i].getObjectNumber());
            com.aspose.imaging.Image resultImage = maskingResults[i].getImage();
            try {
                resultImage.save(dir + outputFileName);
            } finally {
                resultImage.dispose();
            }
        }
    } finally {
        image.dispose();
    }
    

    • Constructor Detail

      • ManualMaskingArgs

        public ManualMaskingArgs()
    • Method Detail

      • getMask

        public final GraphicsPath getMask()

        Gets the set of graphic shapes that form mask.

        Value: The mask.
        Returns:
        the set of graphic shapes that form mask.
      • setMask

        public final void setMask(GraphicsPath value)

        Sets the set of graphic shapes that form mask.

        Value: The mask.
        Parameters:
        value - the set of graphic shapes that form mask.